From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rob Herring Date: Wed, 15 Oct 2014 17:21:00 +0800 Subject: [U-Boot] [PATCH] fdt_support: fix unaligned u64 accesses in fdt_fixup_memory_banks Message-ID: <1413364860-23866-1-git-send-email-robherring2@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Rob Herring 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 Signed-off-by: Rob Herring --- 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