diff mbox series

[1/8] dm: core: add ofnode_for_each_compatible_node()

Message ID 20211013174431.652550-2-michael@walle.cc
State Superseded
Delegated to: Priyanka Jain
Headers show
Series usb: dwc3: add Layerscape SoC support | expand

Commit Message

Michael Walle Oct. 13, 2021, 5:44 p.m. UTC
Add a helper to iterate over all nodes with a given compatible string.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 include/dm/ofnode.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Simon Glass Oct. 14, 2021, 3:11 p.m. UTC | #1
On Wed, 13 Oct 2021 at 11:44, Michael Walle <michael@walle.cc> wrote:
>
> Add a helper to iterate over all nodes with a given compatible string.
>
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  include/dm/ofnode.h | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

Can you add a test for it in test/dm/ofnode.c?
diff mbox series

Patch

diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 6a714d0c7b..0f680e5aa6 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -1009,6 +1009,30 @@  ofnode ofnode_by_prop_value(ofnode from, const char *propname,
 	     ofnode_valid(node); \
 	     node = ofnode_next_subnode(node))
 
+/**
+ * ofnode_for_each_compatible_node() - iterate over all nodes with a given
+ *				       compatible string
+ *
+ * @node:       child node (ofnode, lvalue)
+ * @compat:     compatible string to match
+ *
+ * This is a wrapper around a for loop and is used like so:
+ *
+ *	ofnode node;
+ *
+ *	ofnode_for_each_compatible_node(node, parent, compatible) {
+ *		Use node
+ *		...
+ *	}
+ *
+ * Note that this is implemented as a macro and @node is used as
+ * iterator in the loop.
+ */
+#define ofnode_for_each_compatible_node(node, compat) \
+	for (node = ofnode_by_compatible(ofnode_null(), compat); \
+	     ofnode_valid(node); \
+	     node = ofnode_by_compatible(node, compat))
+
 /**
  * ofnode_get_child_count() - get the child count of a ofnode
  *