Skip to contentSkip to conversation

hw/display/cg3.c: cg3_realizefn: fix memory leak, make FCode loading error fatal and improve error message

PATCH In review Michael Tokarev 2 participants 3 messages May 30, 2015 – Jun 2, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 hw/display/cg3.c: cg3_realizefn: fix memory leak, make FCode loading error fatal and improve error message

---
 hw/display/cg3.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/display/cg3.c +5 -3
index 1e6ff2b..5f869a7 100644
@@ -302,10 +302,12 @@ static void cg3_realizefn(DeviceState *dev, Error **errp)
     if (fcode_filename) {
         ret = load_image_targphys(fcode_filename, s->prom_addr,
                                   FCODE_MAX_ROM_SIZE);
-        if (ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
-            error_report("cg3: could not load prom '%s'", CG3_ROM_FILE);
-        }
     }
+    if (!fcode_filename || ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
+        error_report("cg3: could not load prom '%s'",
+                     fcode_filename ? fcode_filename : CG3_ROM_FILE);
+    }
+    g_free(fcode_filename);
 
     memory_region_init_ram(&s->vram_mem, NULL, "cg3.vram", s->vram_size,
                            &error_abort);
Signature · 1 line
2.1.4
#1 lore raw

Shannon Zhao: can you please add your s-o-b or r-o-b for this version, for this and the next patch?

This started from your original patch which just adds g_free(), later you also added error message improvements to this piece, on my request, but apparently this place needs more tweeking, since failing to load firmware is fatal to the code, so instead of requesting you to change it further I created my version, identical for two files.

Thanks,

/mjt

Quoted 26 lines · Michael Tokarev
---
 hw/display/cg3.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/display/cg3.c +5 -3
index 1e6ff2b..5f869a7 100644
@@ -302,10 +302,12 @@ static void cg3_realizefn(DeviceState *dev, Error **errp)
     if (fcode_filename) {
         ret = load_image_targphys(fcode_filename, s->prom_addr,
                                   FCODE_MAX_ROM_SIZE);
-        if (ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
-            error_report("cg3: could not load prom '%s'", CG3_ROM_FILE);
-        }
     }
+    if (!fcode_filename || ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
+        error_report("cg3: could not load prom '%s'",
+                     fcode_filename ? fcode_filename : CG3_ROM_FILE);
+    }
+    g_free(fcode_filename);
 
     memory_region_init_ram(&s->vram_mem, NULL, "cg3.vram", s->vram_size,
                            &error_abort);
Reviewed-by on v1 1/2
#2 lore raw
In reply to Michael Tokarev
Quoted 1 line · Michael Tokarev
Quoted 25 lines
---
 hw/display/cg3.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/display/cg3.c +5 -3
index 1e6ff2b..5f869a7 100644
@@ -302,10 +302,12 @@ static void cg3_realizefn(DeviceState *dev, Error **errp)
     if (fcode_filename) {
         ret = load_image_targphys(fcode_filename, s->prom_addr,
                                   FCODE_MAX_ROM_SIZE);
-        if (ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
-            error_report("cg3: could not load prom '%s'", CG3_ROM_FILE);
-        }
     }
+    if (!fcode_filename || ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
+        error_report("cg3: could not load prom '%s'",
+                     fcode_filename ? fcode_filename : CG3_ROM_FILE);
+    }
+    g_free(fcode_filename);
 
     memory_region_init_ram(&s->vram_mem, NULL, "cg3.vram", s->vram_size,
                            &error_abort);
Signature · 1 line
Shannon