[U-Boot] [PATCH] fdt_support: fix unaligned u64 accesses in fdt_fixup_memory_banks
Rob Herring
robherring2 at gmail.com
Wed Oct 15 11:21:00 CEST 2014
From: Rob Herring <robh at kernel.org>
Commit f18295d3837c282f (fdt_support: fix an endian bug of
fdt_fixup_memory_banks) changed fdt_fixup_memory_banks cell writing from a
byte at a time to casting the buffer pointer to a 64-bit pointer. This can
result in unaligned accesses when there is a mixture of cell sizes of 1
and 2.
Cc: Masahiro Yamada <yamada.m at jp.panasonic.com>
Signed-off-by: Rob Herring <robh at kernel.org>
---
common/fdt_support.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 3f64156..9c41f3a 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -388,19 +388,22 @@ static int fdt_pack_reg(const void *fdt, void *buf, uint64_t *address,
int i;
int address_len = get_cells_len(fdt, "#address-cells");
int size_len = get_cells_len(fdt, "#size-cells");
+ u64 cell;
char *p = buf;
for (i = 0; i < n; i++) {
if (address_len == 8)
- *(fdt64_t *)p = cpu_to_fdt64(address[i]);
+ cell = cpu_to_fdt64(address[i]);
else
- *(fdt32_t *)p = cpu_to_fdt32(address[i]);
+ cell = cpu_to_fdt32(address[i]);
+ memcpy(p, &cell, address_len);
p += address_len;
if (size_len == 8)
- *(fdt64_t *)p = cpu_to_fdt64(size[i]);
+ cell = cpu_to_fdt64(size[i]);
else
- *(fdt32_t *)p = cpu_to_fdt32(size[i]);
+ cell = cpu_to_fdt32(size[i]);
+ memcpy(p, &cell, size_len);
p += size_len;
}
--
1.9.1
More information about the U-Boot
mailing list