From 2b6e492467c78183bb629bb0a100ea3509b615a5 Mon Sep 17 00:00:00 2001 From: Heikki Krogerus Date: Wed, 23 Jan 2019 17:44:16 +0300 Subject: [PATCH 1/2] device property: Fix the length used in PROPERTY_ENTRY_STRING() With string type property entries we need to use sizeof(const char *) instead of the number of characters as the length of the entry. If the string was shorter then sizeof(const char *), attempts to read it would have failed with -EOVERFLOW. The problem has been hidden because all build-in string properties have had a string longer then 8 characters until now. Fixes: a85f42047533 ("device property: helper macros for property entry creation") Cc: 4.5+ # 4.5+ Signed-off-by: Heikki Krogerus Reviewed-by: Andy Shevchenko Signed-off-by: Rafael J. Wysocki --- include/linux/property.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/property.h b/include/linux/property.h index 3789ec755fb6..65d3420dd5d1 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -258,7 +258,7 @@ struct property_entry { #define PROPERTY_ENTRY_STRING(_name_, _val_) \ (struct property_entry) { \ .name = _name_, \ - .length = sizeof(_val_), \ + .length = sizeof(const char *), \ .type = DEV_PROP_STRING, \ { .value = { .str = _val_ } }, \ } From 344798206f171c5abea7ab1f9762fa526d7f539d Mon Sep 17 00:00:00 2001 From: Heikki Krogerus Date: Wed, 13 Feb 2019 14:55:49 +0300 Subject: [PATCH 2/2] software node: Implement get_named_child_node fwnode callback This makes it possible to support drivers that use fwnode_get_named_child_node() and device_get_named_child_node() functions. The node name is for now taken from a device property named "name". That mimics the old style of naming of the nodes in devicetree (though with modern flattened DT, the name is matched against the actual node-name, it used to be done with a property "name"). In Open Firmware DT the "name" property is also still being used. Signed-off-by: Heikki Krogerus Signed-off-by: Rafael J. Wysocki --- drivers/base/swnode.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 89ad8dee6ad5..1fad9291f6aa 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -499,6 +499,28 @@ software_node_get_next_child(const struct fwnode_handle *fwnode, return &c->fwnode; } +static struct fwnode_handle * +software_node_get_named_child_node(const struct fwnode_handle *fwnode, + const char *childname) +{ + struct software_node *swnode = to_software_node(fwnode); + const struct property_entry *prop; + struct software_node *child; + + if (!swnode || list_empty(&swnode->children)) + return NULL; + + list_for_each_entry(child, &swnode->children, entry) { + prop = property_entry_get(child->properties, "name"); + if (!prop) + continue; + if (!strcmp(childname, prop->value.str)) { + kobject_get(&child->kobj); + return &child->fwnode; + } + } + return NULL; +} static const struct fwnode_operations software_node_ops = { .get = software_node_get, @@ -508,6 +530,7 @@ static const struct fwnode_operations software_node_ops = { .property_read_string_array = software_node_read_string_array, .get_parent = software_node_get_parent, .get_next_child_node = software_node_get_next_child, + .get_named_child_node = software_node_get_named_child_node, }; /* -------------------------------------------------------------------------- */