public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rob Herring <robherring2@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] fdt_support: fix unaligned u64 accesses in fdt_fixup_memory_banks
Date: Wed, 15 Oct 2014 17:21:00 +0800	[thread overview]
Message-ID: <1413364860-23866-1-git-send-email-robherring2@gmail.com> (raw)

From: Rob Herring <robh@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@jp.panasonic.com>
Signed-off-by: Rob Herring <robh@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

             reply	other threads:[~2014-10-15  9:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15  9:21 Rob Herring [this message]
2014-10-24 17:56 ` [U-Boot] [PATCH] fdt_support: fix unaligned u64 accesses in fdt_fixup_memory_banks Simon Glass
2014-10-25  4:51   ` Rob Herring
2014-10-28  0:11     ` Simon Glass
2014-10-28 10:58       ` Måns Rullgård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1413364860-23866-1-git-send-email-robherring2@gmail.com \
    --to=robherring2@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox