qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 2/4] Add error checking for load_image_targphys.
@ 2016-10-16  0:48 Shreya Shrivastava
  2016-10-16 16:55 ` Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: Shreya Shrivastava @ 2016-10-16  0:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: stefanha

Add checks for negative return value to uses of load_image_targphys.
Signed-off-by: Shreya Shrivastava <pink89@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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH 2/4] Add error checking for load_image_targphys.
  2016-10-16  0:48 [Qemu-devel] [PATCH 2/4] Add error checking for load_image_targphys Shreya Shrivastava
@ 2016-10-16 16:55 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2016-10-16 16:55 UTC (permalink / raw)
  To: Shreya Shrivastava; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1899 bytes --]

On Sun, Oct 16, 2016 at 12:48:24AM -0000, Shreya Shrivastava wrote:
> Add checks for negative return value to uses of load_image_targphys.
> Signed-off-by: Shreya Shrivastava <pink89@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)

Your email client is wrapping lines.  git-am(1) cannot apply this patch.

Please use git-send-email(1) as recommended in the guidelines:
http://qemu-project.org/Contribute/SubmitAPatch

>  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);
> +        }

QEMU coding style uses 4-space indentation.  Please run your patches
through scripts/checkpatch.pl to identify coding style issues.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-16 16:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-16  0:48 [Qemu-devel] [PATCH 2/4] Add error checking for load_image_targphys Shreya Shrivastava
2016-10-16 16:55 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).