[rtems commit] libfdt: Check for 8-byte address alignment in fdt_ro_probe_ ()

Sebastian Huber sebh at rtems.org
Thu Dec 16 13:58:33 UTC 2021


Module:    rtems
Branch:    master
Commit:    064a1d76a4f87d8c667488009fa9e9d5f5f0be2a
Changeset: http://git.rtems.org/rtems/commit/?id=064a1d76a4f87d8c667488009fa9e9d5f5f0be2a

Author:    Tom Rini <trini at konsulko.com>
Date:      Wed Nov  4 08:06:05 2020 -0500

libfdt: Check for 8-byte address alignment in fdt_ro_probe_()

The device tree must be loaded in to memory at an 8-byte aligned
address.  Add a check for this condition in fdt_ro_probe_() and a new
error code to return if we are not.

Signed-off-by: Tom Rini <trini at konsulko.com>
Message-Id: <20201104130605.28874-1-trini at konsulko.com>
Signed-off-by: David Gibson <david at gibson.dropbear.id.au>

---

 cpukit/dtc/libfdt/fdt.c | 4 ++++
 cpukit/include/libfdt.h | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/cpukit/dtc/libfdt/fdt.c b/cpukit/dtc/libfdt/fdt.c
index 6cf2fa0..3e89307 100644
--- a/cpukit/dtc/libfdt/fdt.c
+++ b/cpukit/dtc/libfdt/fdt.c
@@ -22,6 +22,10 @@ int32_t fdt_ro_probe_(const void *fdt)
 	if (can_assume(VALID_DTB))
 		return totalsize;
 
+	/* 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) {
 		/* Complete tree */
 		if (!can_assume(LATEST)) {
diff --git a/cpukit/include/libfdt.h b/cpukit/include/libfdt.h
index 5979832..89adee3 100644
--- a/cpukit/include/libfdt.h
+++ b/cpukit/include/libfdt.h
@@ -101,7 +101,11 @@ extern "C" {
 	/* FDT_ERR_BADFLAGS: The function was passed a flags field that
 	 * contains invalid flags or an invalid combination of flags. */
 
-#define FDT_ERR_MAX		18
+#define FDT_ERR_ALIGNMENT	19
+	/* FDT_ERR_ALIGNMENT: The device tree base address is not 8-byte
+	 * aligned. */
+
+#define FDT_ERR_MAX		19
 
 /* constants */
 #define FDT_MAX_PHANDLE 0xfffffffe



More information about the vc mailing list