On Fri, Apr 26, 2013 at 05:43:31AM -0700, Simon Glass wrote:
> 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 <[email protected]>

Nice!

Acked-by: David Gibson <[email protected]>

Jon, please apply.

-- 
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: Digital signature

_______________________________________________
devicetree-discuss mailing list
[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

Reply via email to