dt: introduce of_get_child_by_name to get child node by name
authorSrinivas Kandagatla <srinivas.kandagatla@st.com>
Tue, 18 Sep 2012 07:10:28 +0000 (08:10 +0100)
committerRob Herring <rob.herring@calxeda.com>
Mon, 1 Oct 2012 15:42:21 +0000 (10:42 -0500)
This patch introduces of_get_child_by_name function to get a child node
by its name in a given parent node.

Without this patch each driver code has to iterate the parent and do
a string compare, However having of_get_child_by_name libary function would
avoid code duplication, errors and is more convenient.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
drivers/of/base.c
include/linux/of.h

index c181b94abc363b64a4a38c2e39625b7564dc2267..e2e813624df5980d0f3995cffd3b356e839058ca 100644 (file)
@@ -363,6 +363,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
index 5919ee33f2b7b2d930fa3f6dd877984be5ed5e0d..fabb524d3d755e029536c518a447b9a5dd979753 100644 (file)
@@ -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))
This page took 0.028373 seconds and 5 git commands to generate.