[PATCH 04/29] of: Let of_find_node_by_path iterate over tree

Sascha Hauer s.hauer at pengutronix.de
Tue Feb 26 15:18:31 EST 2013


of_find_node_by_path iterates over the allnodes list. Depending on
where the node we look for is, this can be significantly slower than
using the tree structure to look for a node, so iterate over the tree
instead.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/of/base.c |   37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 704ba8e..1c33be1 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -490,17 +490,40 @@ EXPORT_SYMBOL(of_machine_is_compatible);
  */
 struct device_node *of_find_node_by_path(const char *path)
 {
-	struct device_node *np;
+	char *slash, *p, *freep;
+	struct device_node *dn = root_node;
+
+	if (!root_node)
+		return NULL;
+
+	if (*path != '/')
+		return NULL;
+
+	path++;
 
-	if (!strcmp(path, "/"))
-		return root_node;
+	freep = p = xstrdup(path);
 
-	list_for_each_entry(np, &allnodes, list) {
-		if (np->full_name && (strcmp(np->full_name, path) == 0))
-			return np;
+	while (1) {
+		if (!*p)
+			goto out;
+
+		slash = strchr(p, '/');
+		if (slash)
+			*slash = 0;
+
+		dn = of_find_child_by_name(dn, p);
+		if (!dn)
+			goto out;
+
+		if (!slash)
+			goto out;
+
+		p = slash + 1;
 	}
+out:
+	free(freep);
 
-	return NULL;
+	return dn;
 }
 EXPORT_SYMBOL(of_find_node_by_path);
 
-- 
1.7.10.4




More information about the barebox mailing list