summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-06-01 19:22:40 +0300
committerTom Rini <trini@konsulko.com>2023-07-14 19:54:51 +0300
commit9cf39bbe96753d1099e3626d0c5be1d6e11c7f42 (patch)
treea535c2d3f8faac307fb348940f9308209cbd396b /lib
parent822f7a4543bff59819b6096f1aa1a26f5451bb35 (diff)
downloadu-boot-9cf39bbe96753d1099e3626d0c5be1d6e11c7f42.tar.xz
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')
-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 1b5964d09a..05588d5ed2 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);