diff options
author | Thierry Reding <treding@nvidia.com> | 2014-08-26 15:33:55 (GMT) |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2014-10-22 22:56:41 (GMT) |
commit | 2f3760428ff3c4d5d1a087d016da5943921f0980 (patch) | |
tree | ce1382fa8e07746b958d85db78910c64b48a1c7b /include | |
parent | 9f85eee72a2a3918b2d5cd7b1bf88da69232dede (diff) | |
download | u-boot-fsl-qoriq-2f3760428ff3c4d5d1a087d016da5943921f0980.tar.xz |
fdt: Add a subnodes iterator macro
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>
Diffstat (limited to 'include')
-rw-r--r-- | include/libfdt.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/libfdt.h b/include/libfdt.h index 2dfc6d9..f3cbb63 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -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 */ /**********************************************************************/ |