diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-07-04 08:52:10 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-07-05 08:45:57 +0200 |
commit | 73986cc87d322fcb698f11aee4f0b93401c005a0 (patch) | |
tree | 7fa9587fbb1dd969dd83f9fae09b21a916226a71 | |
parent | 9ab76a48a2b70735d63a1221a2d7b78484fb198a (diff) | |
download | barebox-73986cc87d322fcb698f11aee4f0b93401c005a0.tar.gz |
OF: base: fix inifinite looping in node iterators
of_find_node_by_name suffers from infinite looping, because it
does not check for root node of the tree iterated over. This
fixes this by checking for node->parent to determine whether
the last node has been reached.
Since of_tree_for_each_node does not iterate over the whole tree,
but only over the remaining nodes, rename it to
of_tree_for_each_node_from.
Reported-by: NISHIMOTO Hiroki <hiroki.nishimoto.if@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/of/base.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 63ff6478f4..74d474837f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -33,8 +33,17 @@ * 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) +static inline struct device_node *of_next_node(struct device_node *node) +{ + struct device_node *next; + + next = list_first_entry(&node->list, struct device_node, list); + + return next->parent ? next : NULL; +} + +#define of_tree_for_each_node_from(node, from) \ + for (node = of_next_node(from); node; node = of_next_node(node)) /** * struct alias_prop - Alias property in 'aliases' node @@ -337,7 +346,7 @@ struct device_node *of_find_node_by_name(struct device_node *from, if (!from) from = root_node; - of_tree_for_each_node(np, from) + of_tree_for_each_node_from(np, from) if (np->name && !of_node_cmp(np->name, name)) return np; @@ -367,7 +376,7 @@ struct device_node *of_find_compatible_node(struct device_node *from, if (!from) from = root_node; - of_tree_for_each_node(np, from) + of_tree_for_each_node_from(np, from) if (of_device_is_compatible(np, compatible)) return np; @@ -391,7 +400,7 @@ struct device_node *of_find_node_with_property(struct device_node *from, { struct device_node *np; - of_tree_for_each_node(np, from) { + of_tree_for_each_node_from(np, from) { struct property *pp = of_find_property(np, prop_name, NULL); if (pp) return np; @@ -447,7 +456,7 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from, if (!from) from = root_node; - of_tree_for_each_node(np, from) { + of_tree_for_each_node_from(np, from) { const struct of_device_id *m = of_match_node(matches, np); if (m) { if (match) |