aboutsummaryrefslogtreecommitdiff
path: root/libfdt/fdt.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2009-02-06 14:01:56 +1100
committerGerald Van Baren <vanbaren@cideas.com>2009-04-01 19:29:22 -0400
commit2c0b843e710aa1e2da25c2592e6dbe5d0b0ab7da (patch)
tree5c82846f705799eda5d8d8d1a909c062ecde11eb /libfdt/fdt.c
parented9953d6903c9673135a96ae1644f61cb0eac5ce (diff)
libfdt: Rework fdt_next_node()
Currently fdt_next_node() will find the next node in the blob regardless of whether it is above, below or at the same level in the tree as the starting node - the depth parameter is updated to indicate which is the case. When a depth parameter is supplied, this patch makes it instead terminate immediately when it finds the END_NODE tag for a node at depth 0. In this case it returns the offset immediately past the END_NODE tag. This has a couple of advantages. First, this slightly simplifies fdt_subnode_offset(), which no longer needs to explicitly check that fdt_next_node()'s iteration hasn't left the starting node. Second, this allows fdt_next_node() to be used to implement _fdt_node_end_offset() considerably simplifying the latter function. The other users of fdt_next_node() either don't need to iterate out of the starting node, or don't pass a depth parameter at all. Any callers that really need to iterate out of the starting node, but keep tracking depth can do so by biasing the initial depth value. This is a semantic change, but I think it's very unlikely to break any existing library users. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'libfdt/fdt.c')
-rw-r--r--libfdt/fdt.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index a59a518b0..940cee8b1 100644
--- a/libfdt/fdt.c
+++ b/libfdt/fdt.c
@@ -166,8 +166,8 @@ int fdt_next_node(const void *fdt, int offset, int *depth)
break;
case FDT_END_NODE:
- if (depth)
- (*depth)--;
+ if (depth && ((--(*depth)) < 0))
+ return nextoffset;
break;
case FDT_END: