[PATCH 29/35] libfdt: Add FDT alignment check to fdt_check_header()

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Dec 14 19:38:15 UTC 2021


From: Rob Herring <robh at kernel.org>

Only checking the FDT alignment in fdt_ro_probe_() means that
fdt_check_header() can pass, but then subsequent API calls fail on
alignment checks. Let's add an alignment check to fdt_check_header() so
alignment errors are found up front.

Cc: Tom Rini <trini at konsulko.com>
Cc: Frank Rowand <frowand.list at gmail.com>
Signed-off-by: Rob Herring <robh at kernel.org>
Message-Id: <20210406190712.2118098-1-robh at kernel.org>
Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 cpukit/dtc/libfdt/fdt.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/cpukit/dtc/libfdt/fdt.c b/cpukit/dtc/libfdt/fdt.c
index 3e893073da..9fe7cf4b74 100644
--- a/cpukit/dtc/libfdt/fdt.c
+++ b/cpukit/dtc/libfdt/fdt.c
@@ -90,6 +90,10 @@ int fdt_check_header(const void *fdt)
 {
 	size_t hdrsize;
 
+	/* The device tree must be at an 8-byte aligned address */
+	if ((uintptr_t)fdt & 7)
+		return -FDT_ERR_ALIGNMENT;
+
 	if (fdt_magic(fdt) != FDT_MAGIC)
 		return -FDT_ERR_BADMAGIC;
 	if (!can_assume(LATEST)) {
-- 
2.31.1



More information about the devel mailing list