diff mbox

[U-Boot,3/3] fdt: Fix fdtdec_get_pci_addr() for 64-bit

Message ID 1426852308-13556-3-git-send-email-thierry.reding@gmail.com
State Changes Requested
Delegated to: Simon Glass
Headers show

Commit Message

Thierry Reding March 20, 2015, 11:51 a.m. UTC
From: Thierry Reding <treding@nvidia.com>

The fdtdec_get_pci_addr() implementation uses fdt_addr_to_cpu() to read
cells from an FDT blob. That is wrong because cells are always 32 bits
wide, irrespective of the architecture's address bus width, which does
not apply to fdt_addr_t.

Besides reading the wrong results, this can also cause aborts on 64-bit
architectures that don't allow unaligned accesses to memory. Fix this by
using fdt32_to_cpu() to read the cells instead.

Cc: Hanna Hawa <hannah@marvell.com>
Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 lib/fdtdec.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Simon Glass March 23, 2015, 11:20 p.m. UTC | #1
On 20 March 2015 at 05:51, Thierry Reding <thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> The fdtdec_get_pci_addr() implementation uses fdt_addr_to_cpu() to read
> cells from an FDT blob. That is wrong because cells are always 32 bits
> wide, irrespective of the architecture's address bus width, which does
> not apply to fdt_addr_t.
>
> Besides reading the wrong results, this can also cause aborts on 64-bit
> architectures that don't allow unaligned accesses to memory. Fix this by
> using fdt32_to_cpu() to read the cells instead.
>
> Cc: Hanna Hawa <hannah@marvell.com>
> Cc: Simon Glass <sjg@chromium.org>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index fd244440381e..c26b06f390b8 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -162,13 +162,13 @@  int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
 
 		for (i = 0; i < num; i++) {
 			debug("pci address #%d: %08lx %08lx %08lx\n", i,
-			      (ulong)fdt_addr_to_cpu(cell[0]),
-			      (ulong)fdt_addr_to_cpu(cell[1]),
-			      (ulong)fdt_addr_to_cpu(cell[2]));
+			      (ulong)fdt32_to_cpu(cell[0]),
+			      (ulong)fdt32_to_cpu(cell[1]),
+			      (ulong)fdt32_to_cpu(cell[2]));
 			if ((fdt_addr_to_cpu(*cell) & type) == type) {
-				addr->phys_hi = fdt_addr_to_cpu(cell[0]);
-				addr->phys_mid = fdt_addr_to_cpu(cell[1]);
-				addr->phys_lo = fdt_addr_to_cpu(cell[2]);
+				addr->phys_hi = fdt32_to_cpu(cell[0]);
+				addr->phys_mid = fdt32_to_cpu(cell[1]);
+				addr->phys_lo = fdt32_to_cpu(cell[2]);
 				break;
 			} else {
 				cell += (FDT_PCI_ADDR_CELLS +