[PATCH 05/29] of: remove allnodes list
Sascha Hauer
s.hauer at pengutronix.de
Tue Feb 26 15:18:32 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 1c33be1..d6c346d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -50,8 +50,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;
@@ -628,13 +626,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;
}
@@ -812,8 +810,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);
@@ -825,8 +821,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 59bdc6e..933e855 100644
--- a/include/of.h
+++ b/include/of.h
@@ -65,6 +65,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