[U-Boot] [PATCH 4/5] libfdt: Add fdt_next_subnode() to permit easy subnode iteration

Simon Glass sjg at chromium.org
Tue May 7 18:31:57 CEST 2013


On Mon, May 6, 2013 at 5:31 PM,  <gvb.uboot at gmail.com> wrote:
> From: Simon Glass <sjg at chromium.org>
>
> Iterating through subnodes with libfdt is a little painful to write as we
> need something like this:
>
> for (depth = 0, count = 0,
>         offset = fdt_next_node(fdt, parent_offset, &depth);
>      (offset >= 0) && (depth > 0);
>      offset = fdt_next_node(fdt, offset, &depth)) {
>         if (depth == 1) {
>                 /* code body */
>         }
> }
>
> Using fdt_next_subnode() we can instead write this, which is shorter and
> easier to get right:
>
> for (offset = fdt_first_subnode(fdt, parent_offset);
>      offset >= 0;
>      offset = fdt_next_subnode(fdt, offset)) {
>         /* code body */
> }
>
> Also, it doesn't require two levels of indentation for the loop body.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> Acked-by: David Gibson <david at gibson.dropbear.id.au>

Acked-by: Simon Glass <sjg at chromium.org>


More information about the U-Boot mailing list