Add checks for negative return value to uses of load_image_targphys.
Signed-off-by: Shreya Shrivastava <pin...@sigaint.org>

---
 hw/arm/nseries.c      |  9 +++++++--
 hw/lm32/milkymist.c   | 19 +++++++++++++++----
 hw/ppc/virtex_ml507.c |  5 +++++
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c
index c86cf80..e0b0ae5 100644
--- a/hw/arm/nseries.c
+++ b/hw/arm/nseries.c
@@ -1306,6 +1306,7 @@ static int n810_atag_setup(const struct
arm_boot_info *info, void *p)
 static void n8x0_init(MachineState *machine,
                       struct arm_boot_info *binfo, int model)
 {
+    int rom_size;
     MemoryRegion *sysmem = get_system_memory();
     struct n800_s *s = (struct n800_s *) g_malloc0(sizeof(*s));
     int sdram_size = binfo->ram_size;
@@ -1379,10 +1380,14 @@ static void n8x0_init(MachineState *machine,
          *
          * The code above is for loading the `zImage' file from Nokia
          * images.  */
-        load_image_targphys(option_rom[0].name,
+         rom_size = load_image_targphys(option_rom[0].name,
                             OMAP2_Q2_BASE + 0x400000,
                             sdram_size - 0x400000);
-
+         if (rom_size < 0) {
+                   fprintf(stderr, "qemu: could not load rom file '%s'\n",
+                           option_rom[0].name);
+                   exit(1);
+        }
         n800_setup_nolo_tags(nolo_tags);
         cpu_physical_memory_write(OMAP2_SRAM_BASE, nolo_tags, 0x10000);
         g_free(nolo_tags);
diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index 5cae0f1..2930f0b 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -86,7 +86,7 @@ milkymist_init(MachineState *machine)
     const char *initrd_filename = machine->initrd_filename;
     LM32CPU *cpu;
     CPULM32State *env;
-    int kernel_size;
+    int bios_size, kernel_size;
     DriveInfo *dinfo;
     MemoryRegion *address_space_mem = get_system_memory();
     MemoryRegion *phys_sdram = g_new(MemoryRegion, 1);
@@ -146,9 +146,14 @@ milkymist_init(MachineState *machine)
     bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);

     if (bios_filename) {
-        load_image_targphys(bios_filename, BIOS_OFFSET, BIOS_SIZE);
-    }
+        bios_size = load_image_targphys(bios_filename, BIOS_OFFSET,
BIOS_SIZE);

+        if (bios_size < 0) {
+            fprintf(stderr, "qemu: could not load bios '%s'\n",
+                    bios_filename);
+            exit(1);
+        }
+     }
     reset_info->bootstrap_pc = BIOS_OFFSET;

     /* if no kernel is given no valid bios rom is a fatal error */
@@ -205,9 +210,15 @@ milkymist_init(MachineState *machine)
     }

     if (initrd_filename) {
-        size_t initrd_size;
+        int initrd_size;
         initrd_size = load_image_targphys(initrd_filename, initrd_base,
                 initrd_max);
+
+        if (initrd_size < 0) {
+            fprintf(stderr, "qemu: could not load ram disk '%s'\n",
+                    initrd_filename);
+            exit(1);
+        }
         reset_info->initrd_base = (uint32_t)initrd_base;
         reset_info->initrd_size = (uint32_t)initrd_size;
     }
diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
index b97d966..eec7778 100644
--- a/hw/ppc/virtex_ml507.c
+++ b/hw/ppc/virtex_ml507.c
@@ -269,6 +269,11 @@ static void virtex_init(MachineState *machine)
             kernel_size = load_image_targphys(kernel_filename,
                                               boot_offset,
                                               ram_size);
+            if (kernel_size < 0) {
+                error_report("couldn't load kernel '%s'",
+                              kernel_filename);
+                exit(1);
+            }
             boot_info.bootstrap_pc = boot_offset;
             high = boot_info.bootstrap_pc + kernel_size + 8192;
         }
-- 
1.9.1



Reply via email to