qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v1 1/1] riscv: virt: Cast the initrd start address t


From: Alistair Francis
Subject: [Qemu-devel] [PATCH v1 1/1] riscv: virt: Cast the initrd start address to target bit length
Date: Wed, 21 Nov 2018 22:34:44 +0000

Ensure that the calculate initrd offset points to a valid address for
the architecture.

Signed-off-by: Alistair Francis <address@hidden>
Suggested-by: Alexander Graf <address@hidden>
Reported-by: Alexander Graf <address@hidden>
---
 hw/riscv/virt.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index 2b38f89070..4467195fac 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -85,7 +85,12 @@ static hwaddr load_initrd(const char *filename, uint64_t 
mem_size,
      * halfway into RAM, and for boards with 256MB of RAM or more we put
      * the initrd at 128MB.
      */
-    *start = kernel_entry + MIN(mem_size / 2, 128 * MiB);
+    /* As hwaddr is a 64-bit number we need to cast it for 32-bit */
+#if defined(TARGET_RISCV32)
+    *start = (uint32_t) (kernel_entry + MIN(mem_size / 2, 128ULL * MiB));
+#elif defined(TARGET_RISCV64)
+    *start = (uint64_t) (kernel_entry + MIN(mem_size / 2, 128 * MiB));
+#endif
 
     size = load_ramdisk(filename, *start, mem_size - *start);
     if (size == -1) {
-- 
2.19.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]