aboutsummaryrefslogtreecommitdiff
path: root/lib/of_live.c
diff options
context:
space:
mode:
authorSimon Glass2023-06-01 10:22:40 -0600
committerTom Rini2023-07-14 12:54:51 -0400
commit9cf39bbe96753d1099e3626d0c5be1d6e11c7f42 (patch)
treea535c2d3f8faac307fb348940f9308209cbd396b /lib/of_live.c
parent822f7a4543bff59819b6096f1aa1a26f5451bb35 (diff)
fdt: Align the start of the livetree
Ensure that the block of memory used by live tree is aligned according to the default for structures. This ensures that the root node appears at the start of the block, so it can be used with free(), rather than being 4 bytes later in some cases. This corrects a rather obscure bug in unflatten_device_tree(). Fixes: 8b50d526ea5 ("dm: Add a function to create a 'live' device tree") Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/of_live.c')
-rw-r--r--lib/of_live.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/of_live.c b/lib/of_live.c
index 1b5964d09a9..05588d5ed28 100644
--- a/lib/of_live.c
+++ b/lib/of_live.c
@@ -287,9 +287,12 @@ int unflatten_device_tree(const void *blob, struct device_node **mynodes)
debug(" size is %lx, allocating...\n", size);
/* Allocate memory for the expanded device tree */
- mem = malloc(size + 4);
+ mem = memalign(__alignof__(struct device_node), size + 4);
memset(mem, '\0', size);
+ /* Set up value for dm_test_livetree_align() */
+ *(u32 *)mem = BAD_OF_ROOT;
+
*(__be32 *)(mem + size) = cpu_to_be32(0xdeadbeef);
debug(" unflattening %p...\n", mem);