Add error checking for load_image_targphys.
PATCH 2/4 Add error checking for load_image_targphys.
Add checks for negative return value to uses of load_image_targphys.
--- hw/arm/nseries.c | 9 +++++++-- hw/lm32/milkymist.c | 19 +++++++++++++++---- hw/ppc/virtex_ml507.c | 5 +++++ 3 files changed, 27 insertions(+), 6 deletions(-)
hw/arm/nseries.c +0 -0
@@ -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);hw/lm32/milkymist.c +2 -3
@@ -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;
}hw/ppc/virtex_ml507.c +5 -0
@@ -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 ; }
Signature · 1 line
1.9.1
Quoted 14 lines · Shreya Shrivastava
Add checks for negative return value to uses of
load_image_targphys.Signed-off-by Shreya Shrivastava <[email protected]>--- hw/arm/nseries.c | 9 +++++++-- hw/lm32/milkymist.c | 19 +++++++++++++++---- hw/ppc/virtex_ml507.c | 5 +++++ 3 files changed, 27 insertions(+), 6 deletions(-)hw/arm/nseries.c +0
-0
hw/arm/nseries.c static int n810_atag_setup(const struct · line 1306
Quoted 1 line
hw/arm/nseries.c +0
-0@@ -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
Quoted 11 lines
hw/arm/nseries.c +1
-0static 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;hw/arm/nseries.c +0
-0@@ -1379,10 +1380,14 @@ static void n8x0_init(MachineState *machine,* * The code above is for loading the `zImage' file from Nokia * images. */
hw/arm/nseries.c static void n8x0_init(MachineState *machine, · line 1390
Quoted 10 lines
hw/arm/nseries.c +6
-2-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.