diff options
-rw-r--r-- | drivers/of/base.c | 23 | ||||
-rw-r--r-- | include/linux/of.h | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index c181b94abc36..e2e813624df5 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -364,6 +364,29 @@ struct device_node *of_get_next_child(const struct device_node *node, EXPORT_SYMBOL(of_get_next_child); /** + * of_get_child_by_name - Find the child node by name for a given parent + * @node: parent node + * @name: child name to look for. + * + * This function looks for child node for given matching name + * + * Returns a node pointer if found, with refcount incremented, use + * of_node_put() on it when done. + * Returns NULL if node is not found. + */ +struct device_node *of_get_child_by_name(const struct device_node *node, + const char *name) +{ + struct device_node *child; + + for_each_child_of_node(node, child) + if (child->name && (of_node_cmp(child->name, name) == 0)) + break; + return child; +} +EXPORT_SYMBOL(of_get_child_by_name); + +/** * of_find_node_by_path - Find a node matching a full OF path * @path: The full path to match * diff --git a/include/linux/of.h b/include/linux/of.h index 5919ee33f2b7..fabb524d3d75 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -190,6 +190,8 @@ extern struct device_node *of_get_parent(const struct device_node *node); extern struct device_node *of_get_next_parent(struct device_node *node); extern struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev); +extern struct device_node *of_get_child_by_name(const struct device_node *node, + const char *name); #define for_each_child_of_node(parent, child) \ for (child = of_get_next_child(parent, NULL); child != NULL; \ child = of_get_next_child(parent, child)) |