summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSrinivas Kandagatla <srinivas.kandagatla@st.com>2012-09-18 08:10:28 +0100
committerRob Herring <rob.herring@calxeda.com>2012-10-01 10:42:21 -0500
commit9c19761a7ecdc86abb2fba0feb81e8952eccc1f1 (patch)
tree7da34de41c8b77b9cccf446d53a3943be33b6c3c /drivers
parentee67016fcc58998c44a9c99b0721568b3d2edc6e (diff)
downloadlinux-3.10-9c19761a7ecdc86abb2fba0feb81e8952eccc1f1.tar.gz
linux-3.10-9c19761a7ecdc86abb2fba0feb81e8952eccc1f1.tar.bz2
linux-3.10-9c19761a7ecdc86abb2fba0feb81e8952eccc1f1.zip
dt: introduce of_get_child_by_name to get child node by name
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/of/base.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index c181b94abc3..e2e813624df 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
*