[PATCH 05/37] of: remove allnodes list

Sascha Hauer s.hauer at pengutronix.de
Mon Mar 4 04:53:08 EST 2013


The allnodes list makes it hard to handle multiple devicetrees. Having
a list to iterate over all nodes of a tree is still good to have though.
This patch uses the list_head of the root node as the head of the list.
This way the root node is no longer part of the list, but when iterating
over a tree the root node is not interesting anyway.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/of/base.c |   12 +++++-------
 include/of.h      |    8 ++++++++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 37d3128..ad278ad 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -51,8 +51,6 @@ static LIST_HEAD(aliases_lookup);
 
 static LIST_HEAD(phandle_list);
 
-static LIST_HEAD(allnodes);
-
 struct device_node *root_node;
 
 struct device_node *of_aliases;
@@ -629,13 +627,13 @@ struct device_node *of_new_node(struct device_node *parent, const char *name)
 	if (parent) {
 		node->name = xstrdup(name);
 		node->full_name = asprintf("%s/%s", node->parent->full_name, name);
+		list_add(&node->list, &parent->list);
 	} else {
 		node->name = xstrdup("");
 		node->full_name = xstrdup("");
+		INIT_LIST_HEAD(&node->list);
 	}
 
-	list_add_tail(&node->list, &allnodes);
-
 	return node;
 }
 
@@ -868,8 +866,6 @@ void of_free(struct device_node *node)
 	if (!node)
 		return;
 
-	list_del(&node->list);
-
 	list_for_each_entry_safe(p, pt, &node->properties, list) {
 		list_del(&p->list);
 		free(p->name);
@@ -881,8 +877,10 @@ void of_free(struct device_node *node)
 		of_free(n);
 	}
 
-	if (node->parent)
+	if (node->parent) {
 		list_del(&node->parent_list);
+		list_del(&node->list);
+	}
 
 	if (node->device)
 		node->device->device_node = NULL;
diff --git a/include/of.h b/include/of.h
index f3fc2ae..8166273 100644
--- a/include/of.h
+++ b/include/of.h
@@ -79,6 +79,14 @@ struct fdt_header *fdt_get_tree(void);
 #define device_node_for_nach_child(node, child) \
 	list_for_each_entry(child, &node->children, parent_list)
 
+/*
+ * Iterate over all nodes of a tree. As a devicetree does not
+ * have a dedicated list head, the start node (usually the root
+ * node) will not be iterated over.
+ */
+#define of_tree_for_each_node(node, root) \
+	list_for_each_entry(node, &root->list, list)
+
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
-- 
1.7.10.4




More information about the barebox mailing list