Skip to contentSkip to conversation

hw/ppc: Fix missing return on allocation failure

PATCH Superseded Shivang Upadhyay 2 participants 5 messages Oct 28, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 hw/ppc: Fix missing return on allocation failure

Fixes coverity (CID 1642026)

---
 hw/ppc/spapr_fadump.c | 1 +
 1 file changed, 1 insertion(+)
hw/ppc/spapr_fadump.c +1 -0
index fa3aeac94c..883a60cdcf 100644
@@ -234,6 +234,7 @@ static bool do_preserve_region(FadumpSection *region)
         qemu_log_mask(LOG_GUEST_ERROR,
             "FADump: Failed allocating memory (size: %zu) for copying"
             " reserved memory regions\n", FADUMP_CHUNK_SIZE);
+        return false;
     }
 
     num_chunks = ceil((src_len * 1.0f) / FADUMP_CHUNK_SIZE);
Signature · 1 line
2.51.0
#1 lore raw

PATCH 2/2 hw/ppc: Fix memory leak in get_cpu_state_data()

Fixes coverity (CID 1642024)

---
 hw/ppc/spapr_fadump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_fadump.c +1 -1
index 883a60cdcf..49d2f862a1 100644
@@ -453,7 +453,7 @@ static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu,
 static void *get_cpu_state_data(uint64_t *cpu_state_len)
 {
     FadumpRegSaveAreaHeader reg_save_hdr;
-    FadumpRegEntry *reg_entries;
+    g_autofree FadumpRegEntry *reg_entries;
     FadumpRegEntry *curr_reg_entry;
     CPUState *cpu;
 
Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH 2/2] hw/ppc: Fix memory leak in get_cpu_state_data()

Hi Shivang,

Quoted 17 lines · Shivang Upadhyay

Fixes coverity (CID 1642024)

---
  hw/ppc/spapr_fadump.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_fadump.c +0 -0
index 883a60cdcf..49d2f862a1 100644

hw/ppc/spapr_fadump.c static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu, · line 456

Quoted 5 lines
hw/ppc/spapr_fadump.c +1 -1
@@ -453,7 +453,7 @@ static FadumpRegEntry *populate_cpu_reg_entries(CPUState *cpu,
  static void *get_cpu_state_data(uint64_t *cpu_state_len)
  {
      FadumpRegSaveAreaHeader reg_save_hdr;
-    FadumpRegEntry *reg_entries;
+    g_autofree FadumpRegEntry *reg_entries;

g_autofree pointers have to be NULL-initialized. I don't remember why, likely CPP warnings.

Quoted 3 lines
hw/ppc/spapr_fadump.c +0 -0
      FadumpRegEntry *curr_reg_entry;
      CPUState *cpu;
 
#3 lore raw

Re: [PATCH 2/2] hw/ppc: Fix memory leak in get_cpu_state_data()

Quoted 15 lines · Philippe Mathieu-Daudé

Hi Shivang,

Quoted 12 lines · Shivang Upadhyay

Fixes coverity (CID 1642024)

Cc Aditya Gupta <[email protected]>
Cc Harsh Prateek Bora <[email protected]>
Link https://lore.kernel.org/qemu-devel/ CAFEAcA_Bm52bkPi9MH_uugXRR5fj48RtpbOnPNFQtbX=7Mz_yw@mail.gmail.com/

---
  hw/ppc/spapr_fadump.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

hw/ppc/spapr_fadump.c static FadumpRegEntry · line 457

Quoted 11 lines
hw/ppc/spapr_fadump.c +1 -1
index 883a60cdcf..49d2f862a1 100644
@@ -453,7 +453,7 @@ static FadumpRegEntry 
 *populate_cpu_reg_entries(CPUState *cpu,
   static void *get_cpu_state_data(uint64_t *cpu_state_len)
   {
       FadumpRegSaveAreaHeader reg_save_hdr;
-    FadumpRegEntry *reg_entries;
+    g_autofree FadumpRegEntry *reg_entries;

g_autofree pointers have to be NULL-initialized. I don't remember why, likely CPP warnings.

Ah, see for example commit c8f48b120b3:

As mentioned in docs/devel/style.rst "Automatic memory deallocation":

* Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory

and for full context, commit 821f2967562 ("docs: document use of automatic cleanup functions in glib").

#4 lore raw

Re: [PATCH 2/2] hw/ppc: Fix memory leak in get_cpu_state_data()

Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Philippe Mathieu-Daudé

Hi Shivang,

Quoted 13 lines · Shivang Upadhyay

Fixes coverity (CID 1642024)

CAFEAcA_Bm52bkPi9MH_uugXRR5fj48RtpbOnPNFQtbX=7Mz_yw@mail.gmail.com/

---
  hw/ppc/spapr_fadump.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

hw/ppc/spapr_fadump.c static FadumpRegEntry · line 457

Quoted 11 lines
hw/ppc/spapr_fadump.c +1 -1
index 883a60cdcf..49d2f862a1 100644
@@ -453,7 +453,7 @@ static FadumpRegEntry
 *populate_cpu_reg_entries(CPUState *cpu,
   static void *get_cpu_state_data(uint64_t *cpu_state_len)
   {
       FadumpRegSaveAreaHeader reg_save_hdr;
-    FadumpRegEntry *reg_entries;
+    g_autofree FadumpRegEntry *reg_entries;

g_autofree pointers have to be NULL-initialized. I don't remember why, likely CPP warnings.

Ah, see for example commit c8f48b120b3:

Quoted 7 lines

As mentioned in docs/devel/style.rst "Automatic memory deallocation":

* Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory

and for full context, commit 821f2967562 ("docs: document use of automatic cleanup functions in glib").

Hi Philippe,

Thanks for fix and explaination.
I'll send out v2 soon.

~Shivang.