From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Date: Mon, 18 Aug 2014 12:11:03 -0600 Subject: [U-Boot] [PATCH 05/23] fdt: Add a subnodes iterator macro In-Reply-To: <1408346196-30419-6-git-send-email-thierry.reding@gmail.com> References: <1408346196-30419-1-git-send-email-thierry.reding@gmail.com> <1408346196-30419-6-git-send-email-thierry.reding@gmail.com> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 18 August 2014 01:16, Thierry Reding wrote: > From: Thierry Reding > > 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 Acked-by: Simon Glass Will this go upstream to dtc at some point? > --- > include/libfdt.h | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/include/libfdt.h b/include/libfdt.h > index 4d7fb2681669..0330d7a29a58 100644 > --- a/include/libfdt.h > +++ b/include/libfdt.h > @@ -163,6 +163,26 @@ 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 > + * ... > + * } > + * > + * @fdt: FDT blob > + * @node: child node > + * @parent: parent node It might be worth mentioning the type of each of these since it is not in the macro. > + */ > +#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 */ > /**********************************************************************/ > -- > 2.0.4 > Regards, Simon