On Tue, May 31, 2016 at 10:47:19AM +1000, David Gibson wrote: > On Fri, May 27, 2016 at 10:28:46AM +0200, Maxime Ripard wrote: > > From: Thierry Reding <treding@xxxxxxxxxx> > > > > 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. > > > > Signed-off-by: Thierry Reding <treding@xxxxxxxxxx> > > Signed-off-by: Maxime Ripard <maxime.ripard@xxxxxxxxxxxxxxxxxx> > > Looks good, but needs a testcase. Extending subnode_iterate would > probably make sense. Sorry, one other thing, as I noted on 2/4, I prefer the convention where the loop counter (so the subnode offset in this case) is the first argument to foreach style macros. > > > --- > > libfdt/libfdt.h | 25 +++++++++++++++++++++++++ > > 1 file changed, 25 insertions(+) > > > > diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h > > index 36222fd4a6f4..331f32dd04b5 100644 > > --- a/libfdt/libfdt.h > > +++ b/libfdt/libfdt.h > > @@ -168,6 +168,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 */ > > /**********************************************************************/ > -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Attachment:
signature.asc
Description: PGP signature