summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Elliot Berman <eberman@codeaurora.org> 2021-03-04 23:31:55 -0800
committer Michael Bestas <mkbestas@lineageos.org> 2025-06-15 18:57:38 +0300
commit68dc5cbc945ebc4b3f322684c73ae9851807c256 (patch)
treebde5802be227b9cf257ba59e0fc8e4884372140e
parented1c0063aa676d5c48574c3e1ace5ae70d7c6575 (diff)
libfdt: Add subnode at end of parent
When merging two overlays, the order of the fragments matters because it preserves the order in which the fragments should be applied on the final devicetree. Thus, subnodes should always be added as last child to the parent, not first. Change-Id: Iaff4b8ac0996222318d1e2b8590117249565755b Signed-off-by: Elliot Berman <eberman@codeaurora.org>
-rw-r--r--libfdt/fdt_rw.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c
index 3621d36..e6cd18e 100644
--- a/libfdt/fdt_rw.c
+++ b/libfdt/fdt_rw.c
@@ -339,6 +339,7 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
int err;
uint32_t tag;
fdt32_t *endtag;
+ int depth = 0;
FDT_RW_PROBE(fdt);
@@ -348,15 +349,16 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
else if (offset != -FDT_ERR_NOTFOUND)
return offset;
- /* Try to place the new node after the parent's properties */
- tag = fdt_next_tag(fdt, parentoffset, &nextoffset);
- /* the fdt_subnode_offset_namelen() should ensure this never hits */
- if (!can_assume(LIBFDT_FLAWLESS) && (tag != FDT_BEGIN_NODE))
- return -FDT_ERR_INTERNAL;
+ /* Try to place the new node at the end of the parent */
+ nextoffset = parentoffset;
do {
offset = nextoffset;
tag = fdt_next_tag(fdt, offset, &nextoffset);
- } while ((tag == FDT_PROP) || (tag == FDT_NOP));
+ if (tag == FDT_BEGIN_NODE)
+ depth++;
+ else if (tag == FDT_END_NODE)
+ depth--;
+ } while (depth > 0);
nh = fdt_offset_ptr_w_(fdt, offset);
nodelen = sizeof(*nh) + FDT_TAGALIGN(namelen+1) + FDT_TAGSIZE;