qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Added NULL check for qemu_find_file()
@ 2016-03-12 20:36 rutu.shah.26
  2016-03-14 11:44 ` Stefan Hajnoczi
  2016-03-14 15:34 ` Eric Blake
  0 siblings, 2 replies; 7+ messages in thread
From: rutu.shah.26 @ 2016-03-12 20:36 UTC (permalink / raw)
  To: qemu-devel
  Cc: Rutuja Shah, mark.cave-ayland, agraf, chouteau, blauwirbel,
	qemu-ppc, stefanha, scottwood

From: Rutuja Shah <rutu.shah.26@gmail.com>

This patch adds NULL check for return value from qemu_find_file(), where it is missing. It avoids unnecessary function calls with NULL parameter which in turn return -1. Especially, incase of load_uimage(), two functions are called which return -1 on passing NULL filename.
---
 hw/ppc/e500.c    | 17 +++++++++++++----
 hw/sparc/leon3.c |  6 +++++-
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 09154fa..006adf1 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -1016,15 +1016,24 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
     }
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
 
-    bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL,
-                         1, PPC_ELF_MACHINE, 0, 0);
+    if (filename) {
+        bios_size = load_elf(filename, NULL, NULL, &bios_entry, &loadaddr, NULL,
+                             1, PPC_ELF_MACHINE, 0, 0);
+    } else {
+        bios_size = -1;
+    }
+
     if (bios_size < 0) {
         /*
          * Hrm. No ELF image? Try a uImage, maybe someone is giving us an
          * ePAPR compliant kernel
          */
-        kernel_size = load_uimage(filename, &bios_entry, &loadaddr, NULL,
-                                  NULL, NULL);
+        if (filename) {
+            kernel_size = load_uimage(filename, &bios_entry, &loadaddr, NULL,
+                                      NULL, NULL);
+        } else {
+            kernel_size = -1;
+        }
         if (kernel_size < 0) {
             fprintf(stderr, "qemu: could not load firmware '%s'\n", filename);
             exit(1);
diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index c579f5b..b4e9334 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -168,7 +168,11 @@ static void leon3_generic_hw_init(MachineState *machine)
     }
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
 
-    bios_size = get_image_size(filename);
+    if (filename) {
+        bios_size = get_image_size(filename);
+    } else {
+        bios_size = -1;
+    }
 
     if (bios_size > prom_size) {
         fprintf(stderr, "qemu: could not load prom '%s': file too big\n",

1.9.1

Signed-off-by: Rutuja Shah <rutu.shah.26@gmail.com>

Regards
Rutuja Shah

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

end of thread, other threads:[~2016-03-16 11:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-12 20:36 [Qemu-devel] [PATCH] Added NULL check for qemu_find_file() rutu.shah.26
2016-03-14 11:44 ` Stefan Hajnoczi
2016-03-14 12:59   ` rutuja shah
2016-03-15 12:31     ` Stefan Hajnoczi
2016-03-15 12:56       ` rutuja shah
2016-03-16 11:35         ` Stefan Hajnoczi
2016-03-14 15:34 ` Eric Blake

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).