[PATCH 1/2] of: Add for_each_compatible_node_from iterator

Trent Piepho tpiepho at kymetacorp.com
Fri Dec 18 16:13:59 PST 2015


The existing iterator for_each_compatible_node() searches for each
compatible node starting from the root of the loaded device tree.
This means it only works on the barebox device tree and not the tree
to be passed to the Linux kernel, which is what an of_fixup would
probably want to use.

This adds for_each_compatible_node_from(), which takes an additional
parameter of a root to search from.  This could be the device tree to
be used for the kernel.  It could also be used to search just a
subtree.

Signed-off-by: Trent Piepho <tpiepho at kymetacorp.com>
---

It's possible the fixups in cm_cogent_fixup() and hb_fixup() should
be using this.  It's not clear to me if they want to modify the barebox
device tree or the Linux device tree or both.

 include/of.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/of.h b/include/of.h
index e60fe89..e65a8e8 100644
--- a/include/of.h
+++ b/include/of.h
@@ -641,9 +641,13 @@ static inline struct device_node *of_find_node_by_path_or_alias(
 #define for_each_node_by_name_from(dn, root, name) \
 	for (dn = of_find_node_by_name(root, name); dn; \
 	     dn = of_find_node_by_name(dn, name))
-#define for_each_compatible_node(dn, type, compatible) \
-	for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
+/* Iterate over compatible nodes starting from given root */
+#define for_each_compatible_node_from(dn, root, type, compatible) \
+	for (dn = of_find_compatible_node(root, type, compatible); dn; \
 	     dn = of_find_compatible_node(dn, type, compatible))
+/* Iterate over compatible nodes in default device tree */
+#define for_each_compatible_node(dn, type, compatible) \
+        for_each_compatible_node_from(dn, NULL, type, compatible
 static inline struct device_node *of_find_matching_node(
 	struct device_node *from,
 	const struct of_device_id *matches)
-- 
1.8.3.1




More information about the barebox mailing list