]> git.kernelconcepts.de Git - karo-tx-uboot.git/commit
libfdt: Add fdt_next_subnode() to permit easy subnode iteration
authorSimon Glass <sjg@chromium.org>
Tue, 7 May 2013 06:11:50 +0000 (06:11 +0000)
committerTom Rini <trini@ti.com>
Tue, 14 May 2013 19:37:25 +0000 (15:37 -0400)
commit88f95bbadda89bfaf6a8e817bb66fd114afc1caf
tree17a3c26a6ef0df9a2469c55848a3949bebd3b3d8
parent816cb037adf94ead77593812ccd3244d506175fa
libfdt: Add fdt_next_subnode() to permit easy subnode iteration

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@chromium.org>
(Cherry-picked from dtc commit 4e76ec79)
Acked-by: Gerald Van Baren <vanbaren@cideas.com>
include/libfdt.h
lib/libfdt/fdt.c