]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
fdt: Add a subnodes iterator macro
authorThierry Reding <treding@nvidia.com>
Tue, 26 Aug 2014 15:33:55 +0000 (17:33 +0200)
committerSimon Glass <sjg@chromium.org>
Wed, 22 Oct 2014 22:56:41 +0000 (16:56 -0600)
The fdt_for_each_subnode() iterator macro provided by this patch can be
used to iterate over a device tree node's subnodes. At each iteration a
loop variable will be set to the next subnode.

Acked-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>
include/libfdt.h

index 2dfc6d9e5ce796a232175987d7d51594b869bda8..f3cbb637be419d16c35e59aec1aaf08f7819e310 100644 (file)
@@ -163,6 +163,31 @@ int fdt_first_subnode(const void *fdt, int offset);
  */
 int fdt_next_subnode(const void *fdt, int offset);
 
+/**
+ * fdt_for_each_subnode - iterate over all subnodes of a parent
+ *
+ * This is actually a wrapper around a for loop and would be used like so:
+ *
+ *     fdt_for_each_subnode(fdt, node, parent) {
+ *             ...
+ *             use node
+ *             ...
+ *     }
+ *
+ * Note that this is implemented as a macro and node is used as iterator in
+ * the loop. It should therefore be a locally allocated variable. The parent
+ * variable on the other hand is never modified, so it can be constant or
+ * even a literal.
+ *
+ * @fdt:       FDT blob (const void *)
+ * @node:      child node (int)
+ * @parent:    parent node (int)
+ */
+#define fdt_for_each_subnode(fdt, node, parent)                \
+       for (node = fdt_first_subnode(fdt, parent);     \
+            node >= 0;                                 \
+            node = fdt_next_subnode(fdt, node))
+
 /**********************************************************************/
 /* General functions                                                  */
 /**********************************************************************/