summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2021-04-06 14:07:12 -0500
committerDavid Gibson <david@gibson.dropbear.id.au>2021-04-07 12:44:19 +1000
commitb07b62ee3342db3af74a8bd056dce810764cc7f1 (patch)
tree9f213fd432c2c410a0770463c9824ba60bde53ae
parenta2def5479950d066dcf829b8c1a22874d0aea9a4 (diff)
downloaddevice-tree-compiler-b07b62ee3342db3af74a8bd056dce810764cc7f1.tar.gz
libfdt: Add FDT alignment check to fdt_check_header()
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@konsulko.com> Cc: Frank Rowand <frowand.list@gmail.com> Signed-off-by: Rob Herring <robh@kernel.org> Message-Id: <20210406190712.2118098-1-robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r--libfdt/fdt.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index 3e89307..9fe7cf4 100644
--- a/libfdt/fdt.c
+++ b/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)) {