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);
return 0;
}
DM_TEST(dm_test_ofnode_copy_props_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+
+/* check that the livetree is aligned to a structure boundary */
+static int dm_test_livetree_align(struct unit_test_state *uts)
+{
+ const int align = __alignof__(struct unit_test_state);
+ struct device_node *node;
+ u32 *sentinel;
+ ulong start;
+
+ start = (ulong)gd_of_root();
+ ut_asserteq(start, ALIGN(start, align));
+
+ node = gd_of_root();
+ sentinel = (void *)node - sizeof(u32);
+
+ /*
+ * The sentinel should be overwritten with the root node. If it isn't,
+ * then the root node is not at the very start of the livetree memory
+ * area, and free(root) will fail to free the memory used by the
+ * livetree.
+ */
+ ut_assert(*sentinel != BAD_OF_ROOT);
+
+ return 0;
+}
+DM_TEST(dm_test_livetree_align, UT_TESTF_LIVE_TREE);