public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Fix error handling for callers of
@ 2026-03-10 18:27 Trieu Huynh
  2026-03-10 18:27 ` [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers Trieu Huynh
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Trieu Huynh @ 2026-03-10 18:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Trieu Huynh

From: Trieu Huynh <vikingtc4@gmail.com>

This series audits callers of load_image_targphys(), get_image_size(),
event_notifier_init(), and msix_init() as discussed in issue #413.
The callers are updated to cover negative return value instead of
continuing with invalid state or failure.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413

Trieu Huynh (4):
  hw/core/loader: fix error handling for load_image_targphys callers
  hw/core/loader: fix error handling for get_image_size callers
  util/event_notifier: fix error handling for event_notifier_init
    callers
  hw/pci/msix: fix error handling for msix_init callers

 hw/alpha/dp264.c       |  8 ++++++--
 hw/hppa/machine.c      |  7 +++++--
 hw/hyperv/hyperv.c     |  4 ++--
 hw/hyperv/vmbus.c      |  4 ++--
 hw/ipmi/ipmi_bmc_sim.c |  2 ++
 hw/m68k/next-cube.c    |  9 ++++++++-
 hw/m68k/q800.c         |  7 +++++--
 hw/m68k/virt.c         |  7 +++++--
 hw/microblaze/boot.c   |  4 ++++
 hw/net/igbvf.c         |  2 +-
 hw/net/rocker/rocker.c |  2 +-
 hw/pci/msix.c          |  2 +-
 hw/ppc/amigaone.c      |  9 +++++++++
 hw/ppc/e500.c          | 10 ++++++++++
 hw/ppc/mac_newworld.c  | 10 ++++++++++
 hw/ppc/mac_oldworld.c  | 10 ++++++++++
 hw/ppc/pegasos.c       |  5 +++++
 hw/ppc/pnv.c           | 20 ++++++++++++++++----
 hw/ppc/ppc440_bamboo.c |  4 ++++
 hw/ppc/prep.c          | 10 ++++++++++
 hw/ppc/sam460ex.c      |  5 +++++
 hw/ppc/spapr.c         |  8 ++++++++
 hw/ppc/virtex_ml507.c  |  9 +++++++++
 hw/remote/proxy.c      | 15 +++++++++++++--
 hw/scsi/megasas.c      | 16 +++++++++++-----
 hw/sparc/leon3.c       |  5 +++++
 hw/usb/hcd-xhci-pci.c  | 17 ++++++++++++-----
 hw/vfio/ap.c           |  2 +-
 hw/vfio/ccw.c          |  2 +-
 hw/vfio/pci-quirks.c   |  2 +-
 hw/vfio/pci.c          |  2 +-
 hw/virtio/vhost-vdpa.c |  4 ++--
 32 files changed, 185 insertions(+), 38 deletions(-)

-- 
2.43.0



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

* [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers
  2026-03-10 18:27 [PATCH 0/4] Fix error handling for callers of Trieu Huynh
@ 2026-03-10 18:27 ` Trieu Huynh
  2026-03-10 18:45   ` BALATON Zoltan
  2026-03-10 19:02   ` Aditya Gupta
  2026-03-10 18:27 ` [PATCH 2/4] hw/core/loader: fix error handling for get_image_size callers Trieu Huynh
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 15+ messages in thread
From: Trieu Huynh @ 2026-03-10 18:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Trieu Huynh, Richard Henderson, Helge Deller, Thomas Huth,
	Laurent Vivier, Edgar E. Iglesias, BALATON Zoltan,
	Bernhard Beschow, Mark Cave-Ayland, Nicholas Piggin, Aditya Gupta,
	Glenn Miles, Hervé Poussineau, Harsh Prateek Bora, qemu-ppc

From: Trieu Huynh <vikingtc4@gmail.com>

Check return value of load_image_targphys() and return early on
failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- No functional changes.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
---
 hw/alpha/dp264.c       |  8 ++++++--
 hw/hppa/machine.c      |  7 +++++--
 hw/m68k/next-cube.c    |  9 ++++++++-
 hw/m68k/q800.c         |  7 +++++--
 hw/m68k/virt.c         |  7 +++++--
 hw/microblaze/boot.c   |  4 ++++
 hw/ppc/amigaone.c      |  9 +++++++++
 hw/ppc/e500.c          | 10 ++++++++++
 hw/ppc/mac_newworld.c  | 10 ++++++++++
 hw/ppc/mac_oldworld.c  | 10 ++++++++++
 hw/ppc/pegasos.c       |  5 +++++
 hw/ppc/pnv.c           | 20 ++++++++++++++++----
 hw/ppc/ppc440_bamboo.c |  4 ++++
 hw/ppc/prep.c          | 10 ++++++++++
 hw/ppc/sam460ex.c      |  5 +++++
 hw/ppc/spapr.c         |  8 ++++++++
 hw/ppc/virtex_ml507.c  |  9 +++++++++
 17 files changed, 129 insertions(+), 13 deletions(-)

diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index 98219f0456..830d14a509 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -189,8 +189,12 @@ static void clipper_init(MachineState *machine)
 
             /* Put the initrd image as high in memory as possible.  */
             initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK;
-            load_image_targphys(initrd_filename, initrd_base,
-                                ram_size - initrd_base, NULL);
+            if (load_image_targphys(initrd_filename, initrd_base,
+                                ram_size - initrd_base, NULL) < 0) {
+                error_report("could not load initrd '%s'",
+                             initrd_filename);
+                exit(1);
+            }
 
             address_space_stq_le(&address_space_memory, param_offset + 0x100,
                                  initrd_base + 0xfffffc0000000000ULL,
diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
index f55e84529f..0bf3bccb07 100644
--- a/hw/hppa/machine.c
+++ b/hw/hppa/machine.c
@@ -507,8 +507,11 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
                 exit(1);
             }
 
-            load_image_targphys(initrd_filename, initrd_base, initrd_size,
-                                NULL);
+            if (load_image_targphys(initrd_filename, initrd_base, initrd_size,
+                                NULL) < 0) {
+                error_report("Could not load initrd '%s'", initrd_filename);
+                exit(1);
+            }
             cpu[0]->env.initrd_base = initrd_base;
             cpu[0]->env.initrd_end  = initrd_base + initrd_size;
         }
diff --git a/hw/m68k/next-cube.c b/hw/m68k/next-cube.c
index 26177c7b86..77a88d1dde 100644
--- a/hw/m68k/next-cube.c
+++ b/hw/m68k/next-cube.c
@@ -1326,7 +1326,14 @@ static void next_cube_init(MachineState *machine)
     memory_region_init_alias(&m->rom2, NULL, "next.rom2", &m->rom, 0x0,
                              0x20000);
     memory_region_add_subregion(sysmem, 0x0, &m->rom2);
-    if (load_image_targphys(bios_name, 0x01000000, 0x20000, NULL) < 8) {
+    int bios_size = 0;
+    bios_size = load_image_targphys(bios_name, 0x01000000, 0x20000, NULL);
+    if (bios_size <  0) {
+        /* Shoud report failure and exit regardless of qtest enabled or not */
+        error_report("Failed to load firmware (bios size < 0) '%s'.",
+                     bios_name);
+        exit(1);
+    } else if (bios_size < 8) {
         if (!qtest_enabled()) {
             error_report("Failed to load firmware '%s'.", bios_name);
         }
diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index ded531394e..3266617ad7 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -632,8 +632,11 @@ static void q800_machine_init(MachineState *machine)
             }
 
             initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK;
-            load_image_targphys(initrd_filename, initrd_base,
-                                ram_size - initrd_base, NULL);
+            if (load_image_targphys(initrd_filename, initrd_base,
+                                ram_size - initrd_base, NULL) < 0) {
+                error_report("Could not load initrd '%s'", initrd_filename);
+                exit(1);
+            }
             BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base,
                       initrd_size);
         } else {
diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index e67900c727..90f52f26e5 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -291,8 +291,11 @@ static void virt_init(MachineState *machine)
             }
 
             initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK;
-            load_image_targphys(initrd_filename, initrd_base,
-                                ram_size - initrd_base, NULL);
+            if (load_image_targphys(initrd_filename, initrd_base,
+                                ram_size - initrd_base, NULL) < 0) {
+                error_report("Could not load initrd '%s'", initrd_filename);
+                exit(1);
+            }
             BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base,
                       initrd_size);
         } else {
diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c
index a6f9ebab90..9fa8885dd3 100644
--- a/hw/microblaze/boot.c
+++ b/hw/microblaze/boot.c
@@ -172,6 +172,10 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, bool is_little_endian,
         if (kernel_size < 0) {
             kernel_size = load_image_targphys(kernel_filename, ddr_base,
                                               ramsize, NULL);
+            if (kernel_size < 0) {
+                error_report("could not load kernel '%s'", kernel_filename);
+                exit(EXIT_FAILURE);
+            }
             boot_info.bootstrap_pc = ddr_base;
             high = (ddr_base + kernel_size + 3) & ~3;
         }
diff --git a/hw/ppc/amigaone.c b/hw/ppc/amigaone.c
index 8074713fbe..bb5e712c1b 100644
--- a/hw/ppc/amigaone.c
+++ b/hw/ppc/amigaone.c
@@ -326,6 +326,10 @@ static void amigaone_init(MachineState *machine)
             exit(1);
         }
         sz = load_image_targphys(filename, PROM_ADDR, PROM_SIZE, &error_fatal);
+        if (sz < 0) {
+            error_report("Could not load firmware '%s'", filename);
+            exit(1);
+        }
     }
 
     /* Articia S */
@@ -411,6 +415,11 @@ static void amigaone_init(MachineState *machine)
         loadaddr = MAX(loadaddr, INITRD_MIN_ADDR);
         sz = load_image_targphys(machine->initrd_filename, loadaddr,
                                  bi->bd_info - loadaddr, &error_fatal);
+        if (sz < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
         bi->initrd_start = loadaddr;
         bi->initrd_end = loadaddr + sz;
     }
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index d6ca2e8563..3117a05b59 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -1221,6 +1221,11 @@ void ppce500_init(MachineState *machine)
         kernel_size = load_image_targphys(machine->kernel_filename,
                                       cur_base, machine->ram_size - cur_base,
                                       &error_fatal);
+        if (kernel_size < 0) {
+            error_report("Could not load kernel '%s'",
+                         machine->kernel_filename);
+            exit(1);
+        }
         cur_base += kernel_size;
     }
 
@@ -1230,6 +1235,11 @@ void ppce500_init(MachineState *machine)
         initrd_size = load_image_targphys(machine->initrd_filename, initrd_base,
                                           machine->ram_size - initrd_base,
                                           &error_fatal);
+        if (initrd_size < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
         cur_base = initrd_base + initrd_size;
     }
 
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index 3680d96ed3..5e9556af33 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -213,6 +213,11 @@ static void ppc_core99_init(MachineState *machine)
                                               kernel_base,
                                               machine->ram_size - kernel_base,
                                               &error_fatal);
+            if (kernel_size < 0) {
+                error_report("Could not load kernel '%s'",
+                             machine->kernel_filename);
+                exit(1);
+            }
         }
         /* load initrd */
         if (machine->initrd_filename) {
@@ -221,6 +226,11 @@ static void ppc_core99_init(MachineState *machine)
                                               initrd_base,
                                               machine->ram_size - initrd_base,
                                               &error_fatal);
+            if (initrd_size < 0) {
+                error_report("Could not load initrd '%s'",
+                             machine->initrd_filename);
+                exit(1);
+            }
             cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
         } else {
             cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP);
diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c
index 24d9f2e3d5..fdbbfed52a 100644
--- a/hw/ppc/mac_oldworld.c
+++ b/hw/ppc/mac_oldworld.c
@@ -169,6 +169,11 @@ static void ppc_heathrow_init(MachineState *machine)
                                               kernel_base,
                                               machine->ram_size - kernel_base,
                                               &error_fatal);
+            if (kernel_size < 0) {
+                error_report("Could not load kernel '%s'",
+                             machine->kernel_filename);
+                exit(1);
+            }
         }
         /* load initrd */
         if (machine->initrd_filename) {
@@ -178,6 +183,11 @@ static void ppc_heathrow_init(MachineState *machine)
                                               initrd_base,
                                               machine->ram_size - initrd_base,
                                               &error_fatal);
+            if (initrd_size < 0) {
+                error_report("Could not load initrd '%s'",
+                             machine->initrd_filename);
+                exit(1);
+            }
             cmdline_base = TARGET_PAGE_ALIGN(initrd_base + initrd_size);
         } else {
             cmdline_base = TARGET_PAGE_ALIGN(kernel_base + kernel_size + KERNEL_GAP);
diff --git a/hw/ppc/pegasos.c b/hw/ppc/pegasos.c
index ac9fc5a654..0f03691f52 100644
--- a/hw/ppc/pegasos.c
+++ b/hw/ppc/pegasos.c
@@ -304,6 +304,11 @@ static void pegasos_init(MachineState *machine)
         pm->initrd_addr = MAX(pm->initrd_addr, INITRD_MIN_ADDR);
         sz = load_image_targphys(machine->initrd_filename, pm->initrd_addr,
                             machine->ram_size - pm->initrd_addr, &error_fatal);
+        if (sz < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
         pm->initrd_size = sz;
     }
 
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index 1513575b8f..aecffb211b 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -1068,14 +1068,21 @@ static void pnv_init(MachineState *machine)
         exit(1);
     }
 
-    load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
-                        &error_fatal);
+    if (load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
+                        &error_fatal) < 0) {
+        error_report("Could not load OPAL firmware '%s'", fw_filename);
+        exit(1);
+    }
     g_free(fw_filename);
 
     /* load kernel */
     if (machine->kernel_filename) {
-        load_image_targphys(machine->kernel_filename,
-                            KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, &error_fatal);
+        if (load_image_targphys(machine->kernel_filename,
+                        KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, &error_fatal) < 0) {
+            error_report("Could not load kernel '%s'",
+                         machine->kernel_filename);
+            exit(1);
+        }
     }
 
     /* load initrd */
@@ -1084,6 +1091,11 @@ static void pnv_init(MachineState *machine)
         pnv->initrd_size = load_image_targphys(machine->initrd_filename,
                                                pnv->initrd_base,
                                                INITRD_MAX_SIZE, &error_fatal);
+        if (pnv->initrd_size < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
     }
 
     /* load dtb if passed */
diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c
index 2dde008b0e..b9c30d8929 100644
--- a/hw/ppc/ppc440_bamboo.c
+++ b/hw/ppc/ppc440_bamboo.c
@@ -244,6 +244,10 @@ static void bamboo_init(MachineState *machine)
         initrd_size = load_image_targphys(initrd_filename, RAMDISK_ADDR,
                                           machine->ram_size - RAMDISK_ADDR,
                                           &error_fatal);
+        if (initrd_size < 0) {
+            error_report("Could not load initrd '%s'", initrd_filename);
+            exit(1);
+        }
     }
 
     /* If we're loading a kernel directly, we must load the device tree too. */
diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
index e973b34099..172a4afd71 100644
--- a/hw/ppc/prep.c
+++ b/hw/ppc/prep.c
@@ -382,6 +382,11 @@ static void ibm_40p_init(MachineState *machine)
                                           kernel_base,
                                           machine->ram_size - kernel_base,
                                           &error_fatal);
+        if (kernel_size < 0) {
+            error_report("Could not load kernel '%s'",
+                         machine->kernel_filename);
+            exit(1);
+        }
         fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
         fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
         /* load initrd */
@@ -391,6 +396,11 @@ static void ibm_40p_init(MachineState *machine)
                                               initrd_base,
                                               machine->ram_size - initrd_base,
                                               &error_fatal);
+            if (initrd_size < 0) {
+                error_report("Could not load initrd '%s'",
+                             machine->initrd_filename);
+                exit(1);
+            }
             fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_base);
             fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
         }
diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c
index b13dd224ba..0747555bc8 100644
--- a/hw/ppc/sam460ex.c
+++ b/hw/ppc/sam460ex.c
@@ -493,6 +493,11 @@ static void sam460ex_init(MachineState *machine)
                                           RAMDISK_ADDR,
                                           machine->ram_size - RAMDISK_ADDR,
                                           &error_fatal);
+        if (initrd_size < 0) {
+            error_report("Could not load initrd '%s'",
+                         machine->initrd_filename);
+            exit(1);
+        }
     }
 
     /* If we're loading a kernel directly, we must load the device tree too. */
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 0ab39dfea6..7ab6a47c5b 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2865,6 +2865,10 @@ static void spapr_machine_init(MachineState *machine)
         exit(1);
     }
     fw_size = load_image_targphys(filename, 0, FW_MAX_SIZE, &error_fatal);
+    if (fw_size < 0) {
+        error_report("Could not load LPAR firmware '%s'", filename);
+        exit(1);
+    }
 
     /*
      * if Secure VM (PEF) support is configured, then initialize it
@@ -3124,6 +3128,10 @@ static void spapr_machine_init(MachineState *machine)
                                                 spapr->initrd_base,
                                                 load_limit - spapr->initrd_base,
                                                 &error_fatal);
+            if (spapr->initrd_size < 0) {
+                error_report("Could not load initrd '%s'", initrd_filename);
+                exit(1);
+            }
         }
     }
 
diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c
index 51b3d7d712..b125561dd6 100644
--- a/hw/ppc/virtex_ml507.c
+++ b/hw/ppc/virtex_ml507.c
@@ -255,6 +255,10 @@ static void virtex_init(MachineState *machine)
             kernel_size = load_image_targphys(kernel_filename,
                                               boot_offset,
                                               machine->ram_size, &error_fatal);
+            if (kernel_size < 0) {
+                error_report("could not load kernel '%s'", kernel_filename);
+                exit(1);
+            }
             boot_info.bootstrap_pc = boot_offset;
             high = boot_info.bootstrap_pc + kernel_size + 8192;
         }
@@ -267,6 +271,11 @@ static void virtex_init(MachineState *machine)
             initrd_size = load_image_targphys(machine->initrd_filename,
                                               high, machine->ram_size - high,
                                               &error_fatal);
+            if (initrd_size < 0) {
+                error_report("could not load initrd '%s'",
+                             machine->initrd_filename);
+                exit(1);
+            }
             high = ROUND_UP(high + initrd_size, 4);
         }
 
-- 
2.43.0



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

* [PATCH 2/4] hw/core/loader: fix error handling for get_image_size callers
  2026-03-10 18:27 [PATCH 0/4] Fix error handling for callers of Trieu Huynh
  2026-03-10 18:27 ` [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers Trieu Huynh
@ 2026-03-10 18:27 ` Trieu Huynh
  2026-03-11  8:13   ` Clément Chigot
  2026-03-10 18:27 ` [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers Trieu Huynh
  2026-03-10 18:28 ` [PATCH 4/4] hw/pci/msix: fix error handling for msix_init callers Trieu Huynh
  3 siblings, 1 reply; 15+ messages in thread
From: Trieu Huynh @ 2026-03-10 18:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Trieu Huynh, Corey Minyard, Clément Chigot, Frederic Konrad,
	Mark Cave-Ayland, Artyom Tarasenko

From: Trieu Huynh <vikingtc4@gmail.com>

Check return value of get_image_size() and return early on
failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- No functional changes.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
---
 hw/ipmi/ipmi_bmc_sim.c | 2 ++
 hw/sparc/leon3.c       | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
index 012e2ee4fe..fd875491f5 100644
--- a/hw/ipmi/ipmi_bmc_sim.c
+++ b/hw/ipmi/ipmi_bmc_sim.c
@@ -2561,6 +2561,8 @@ static void ipmi_fru_init(IPMIFru *fru)
             g_free(fru->data);
             fru->data = NULL;
         }
+    } else {
+        error_report("Could not get file size '%s'", fru->filename);
     }
 
 out:
diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 9147d56bd4..c821dfd3bb 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -354,6 +354,11 @@ static void leon3_generic_hw_init(MachineState *machine)
     } else {
         bios_size = -1;
     }
+    if (bios_size < 0) {
+        error_report("could not found or failed to get file size: '%s'",
+                     filename);
+        exit(1);
+    }
 
     if (bios_size > prom_size) {
         error_report("could not load prom '%s': file too big", filename);
-- 
2.43.0



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

* [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers
  2026-03-10 18:27 [PATCH 0/4] Fix error handling for callers of Trieu Huynh
  2026-03-10 18:27 ` [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers Trieu Huynh
  2026-03-10 18:27 ` [PATCH 2/4] hw/core/loader: fix error handling for get_image_size callers Trieu Huynh
@ 2026-03-10 18:27 ` Trieu Huynh
  2026-03-11 10:47   ` Anthony Krowiak
  2026-03-11 16:01   ` Jag Raman
  2026-03-10 18:28 ` [PATCH 4/4] hw/pci/msix: fix error handling for msix_init callers Trieu Huynh
  3 siblings, 2 replies; 15+ messages in thread
From: Trieu Huynh @ 2026-03-10 18:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Trieu Huynh, Maciej S. Szmigiero, Elena Ufimtseva,
	Jagannathan Raman, Thomas Huth, Alex Williamson,
	Cédric Le Goater, Tony Krowiak, Halil Pasic, Jason Herne,
	Eric Farman, Matthew Rosato, Michael S. Tsirkin,
	Stefano Garzarella, qemu-s390x

From: Trieu Huynh <vikingtc4@gmail.com>

Check return value of event_notifier_init() and return early on
failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- No functional changes.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
---
 hw/hyperv/hyperv.c     |  4 ++--
 hw/hyperv/vmbus.c      |  4 ++--
 hw/remote/proxy.c      | 15 +++++++++++++--
 hw/vfio/ap.c           |  2 +-
 hw/vfio/ccw.c          |  2 +-
 hw/vfio/pci-quirks.c   |  2 +-
 hw/vfio/pci.c          |  2 +-
 hw/virtio/vhost-vdpa.c |  4 ++--
 8 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c
index 27e323a819..aa278b179e 100644
--- a/hw/hyperv/hyperv.c
+++ b/hw/hyperv/hyperv.c
@@ -439,7 +439,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
         sint_route->staged_msg->cb_data = cb_data;
 
         r = event_notifier_init(ack_notifier, false);
-        if (r) {
+        if (r < 0) {
             goto cleanup_err_sint;
         }
         event_notifier_set_handler(ack_notifier, sint_ack_handler);
@@ -453,7 +453,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
 
     /* We need to setup a GSI for this SintRoute */
     r = event_notifier_init(&sint_route->sint_set_notifier, false);
-    if (r) {
+    if (r < 0) {
         goto cleanup_err_sint;
     }
 
diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
index c5bab5d245..2f0d2a03d8 100644
--- a/hw/hyperv/vmbus.c
+++ b/hw/hyperv/vmbus.c
@@ -1425,7 +1425,7 @@ static void open_channel(VMBusChannel *chan)
         goto put_gpadl;
     }
 
-    if (event_notifier_init(&chan->notifier, 0)) {
+    if (event_notifier_init(&chan->notifier, 0) < 0) {
         goto put_gpadl;
     }
 
@@ -2416,7 +2416,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
     }
 
     ret = event_notifier_init(&vmbus->notifier, 0);
-    if (ret != 0) {
+    if (ret < 0) {
         error_setg(errp, "event notifier failed to init with %d", ret);
         goto remove_msg_handler;
     }
diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c
index 5081d67e7f..e91566509f 100644
--- a/hw/remote/proxy.c
+++ b/hw/remote/proxy.c
@@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev)
     PCIDevice *pci_dev = PCI_DEVICE(dev);
     MPQemuMsg msg;
     Error *local_err = NULL;
+    int ret = 0;
 
-    event_notifier_init(&dev->intr, 0);
-    event_notifier_init(&dev->resample, 0);
+    ret = event_notifier_init(&dev->intr, 0);
+    if (ret < 0) {
+        error_report("Failed to init intr notifier: %s", strerror(-ret));
+        return;
+    }
+
+    ret = event_notifier_init(&dev->resample, 0);
+    if (ret < 0) {
+        error_report("Failed to init resample notifier: %s", strerror(-ret));
+        event_notifier_cleanup(&dev->intr);
+        return;
+    }
 
     memset(&msg, 0, sizeof(MPQemuMsg));
     msg.cmd = MPQEMU_CMD_SET_IRQFD;
diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
index e58a0169af..5c8f305653 100644
--- a/hw/vfio/ap.c
+++ b/hw/vfio/ap.c
@@ -180,7 +180,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
         return false;
     }
 
-    if (event_notifier_init(notifier, 0)) {
+    if (event_notifier_init(notifier, 0) < 0) {
         error_setg_errno(errp, errno,
                          "vfio: Unable to init event notifier for irq (%d)",
                          irq);
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index 2251facb35..ce9c014e6a 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -418,7 +418,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
         return false;
     }
 
-    if (event_notifier_init(notifier, 0)) {
+    if (event_notifier_init(notifier, 0) < 0) {
         error_setg_errno(errp, errno,
                          "vfio: Unable to init event notifier for irq (%d)",
                          irq);
diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index 7b907b9360..66e02b15a4 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -318,7 +318,7 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevice *vdev,
 
     ioeventfd = g_malloc0(sizeof(*ioeventfd));
 
-    if (event_notifier_init(&ioeventfd->e, 0)) {
+    if (event_notifier_init(&ioeventfd->e, 0) < 0) {
         g_free(ioeventfd);
         return NULL;
     }
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index c89f3fbea3..29bf6511b3 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -70,7 +70,7 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e,
     }
 
     ret = event_notifier_init(e, 0);
-    if (ret) {
+    if (ret < 0) {
         error_setg_errno(errp, -ret, "vfio_notifier_init %s failed", name);
         return false;
     }
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 2f8f11df86..9c7634e243 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -1075,13 +1075,13 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,
     int r;
 
     r = event_notifier_init(&svq->hdev_kick, 0);
-    if (r != 0) {
+    if (r < 0) {
         error_setg_errno(errp, -r, "Couldn't create kick event notifier");
         goto err_init_hdev_kick;
     }
 
     r = event_notifier_init(&svq->hdev_call, 0);
-    if (r != 0) {
+    if (r < 0) {
         error_setg_errno(errp, -r, "Couldn't create call event notifier");
         goto err_init_hdev_call;
     }
-- 
2.43.0



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

* [PATCH 4/4] hw/pci/msix: fix error handling for msix_init callers
  2026-03-10 18:27 [PATCH 0/4] Fix error handling for callers of Trieu Huynh
                   ` (2 preceding siblings ...)
  2026-03-10 18:27 ` [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers Trieu Huynh
@ 2026-03-10 18:28 ` Trieu Huynh
  2026-03-11  5:52   ` Akihiko Odaki
  3 siblings, 1 reply; 15+ messages in thread
From: Trieu Huynh @ 2026-03-10 18:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: Trieu Huynh, Akihiko Odaki, Sriram Yagnaraman, Jason Wang,
	Jiri Pirko, Michael S. Tsirkin, Marcel Apfelbaum, Paolo Bonzini,
	Fam Zheng, Hannes Reinecke, qemu-block

From: Trieu Huynh <vikingtc4@gmail.com>

Check return value of msix_init() and return early on
failure instead of continuing with invalid state.
- Use ret < 0 to handle negative return value.
- No functional changes.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
---
 hw/net/igbvf.c         |  2 +-
 hw/net/rocker/rocker.c |  2 +-
 hw/pci/msix.c          |  2 +-
 hw/scsi/megasas.c      | 16 +++++++++++-----
 hw/usb/hcd-xhci-pci.c  | 17 ++++++++++++-----
 5 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/hw/net/igbvf.c b/hw/net/igbvf.c
index 48d56e43ac..9a165c7063 100644
--- a/hw/net/igbvf.c
+++ b/hw/net/igbvf.c
@@ -260,7 +260,7 @@ static void igbvf_pci_realize(PCIDevice *dev, Error **errp)
 
     ret = msix_init(dev, IGBVF_MSIX_VEC_NUM, &s->msix, IGBVF_MSIX_BAR_IDX, 0,
         &s->msix, IGBVF_MSIX_BAR_IDX, 0x2000, 0x70, errp);
-    if (ret) {
+    if (ret < 0) {
         return;
     }
 
diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
index 4a7056bd45..910dce901b 100644
--- a/hw/net/rocker/rocker.c
+++ b/hw/net/rocker/rocker.c
@@ -1228,7 +1228,7 @@ static int rocker_msix_init(Rocker *r, Error **errp)
                     &r->msix_bar,
                     ROCKER_PCI_MSIX_BAR_IDX, ROCKER_PCI_MSIX_PBA_OFFSET,
                     0, errp);
-    if (err) {
+    if (err < 0) {
         return err;
     }
 
diff --git a/hw/pci/msix.c b/hw/pci/msix.c
index b35476d057..1b23eaf100 100644
--- a/hw/pci/msix.c
+++ b/hw/pci/msix.c
@@ -432,7 +432,7 @@ int msix_init_exclusive_bar(PCIDevice *dev, uint32_t nentries,
                     0, &dev->msix_exclusive_bar,
                     bar_nr, bar_pba_offset,
                     0, errp);
-    if (ret) {
+    if (ret < 0) {
         return ret;
     }
 
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index f62e420a91..90d397374e 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -2380,11 +2380,17 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
     memory_region_init_io(&s->queue_io, OBJECT(s), &megasas_queue_ops, s,
                           "megasas-queue", 0x40000);
 
-    if (megasas_use_msix(s) &&
-        msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000,
-                  &s->mmio_io, b->mmio_bar, 0x3800, 0x68, NULL)) {
-        /* TODO: check msix_init's error, and should fail on msix=on */
-        s->msix = ON_OFF_AUTO_OFF;
+    if (megasas_use_msix(s)) {
+        ret = msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000,
+                        &s->mmio_io, b->mmio_bar, 0x3800, 0x68, NULL);
+
+        if (ret < 0) {
+            if (s->msix == ON_OFF_AUTO_ON) {
+                error_setg(errp, "MSI-X initialization failed");
+                return;
+            }
+            s->msix = ON_OFF_AUTO_OFF;
+        }
     }
 
     if (pci_is_express(dev)) {
diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c
index aa570506fc..7bd4425b34 100644
--- a/hw/usb/hcd-xhci-pci.c
+++ b/hw/usb/hcd-xhci-pci.c
@@ -173,11 +173,18 @@ static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp)
     }
 
     if (s->msix != ON_OFF_AUTO_OFF) {
-        /* TODO check for errors, and should fail when msix=on */
-        msix_init(dev, s->xhci.numintrs,
-                  &s->xhci.mem, 0, OFF_MSIX_TABLE,
-                  &s->xhci.mem, 0, OFF_MSIX_PBA,
-                  0x90, NULL);
+        ret = msix_init(dev, s->xhci.numintrs,
+                        &s->xhci.mem, 0, OFF_MSIX_TABLE,
+                        &s->xhci.mem, 0, OFF_MSIX_PBA,
+                        0x90, NULL);
+
+        if (ret < 0) {
+            if (s->msix == ON_OFF_AUTO_ON) {
+                error_setg(errp, "MSI-X initialization failed");
+                return;
+            }
+            s->msix = ON_OFF_AUTO_OFF;
+        }
     }
     s->xhci.as = pci_get_address_space(dev);
 }
-- 
2.43.0



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

* Re: [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers
  2026-03-10 18:27 ` [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers Trieu Huynh
@ 2026-03-10 18:45   ` BALATON Zoltan
  2026-03-10 19:02   ` Aditya Gupta
  1 sibling, 0 replies; 15+ messages in thread
From: BALATON Zoltan @ 2026-03-10 18:45 UTC (permalink / raw)
  To: Trieu Huynh
  Cc: qemu-devel, Richard Henderson, Helge Deller, Thomas Huth,
	Laurent Vivier, Edgar E. Iglesias, Bernhard Beschow,
	Mark Cave-Ayland, Nicholas Piggin, Aditya Gupta, Glenn Miles,
	Hervé Poussineau, Harsh Prateek Bora, qemu-ppc

On Wed, 11 Mar 2026, Trieu Huynh wrote:
> From: Trieu Huynh <vikingtc4@gmail.com>
>
> Check return value of load_image_targphys() and return early on
> failure instead of continuing with invalid state.
> - Use ret < 0 to handle negative return value.
> - No functional changes.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
> Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
> ---
> hw/alpha/dp264.c       |  8 ++++++--
> hw/hppa/machine.c      |  7 +++++--
> hw/m68k/next-cube.c    |  9 ++++++++-
> hw/m68k/q800.c         |  7 +++++--
> hw/m68k/virt.c         |  7 +++++--
> hw/microblaze/boot.c   |  4 ++++

I don't know about these above,

> hw/ppc/amigaone.c      |  9 +++++++++
> hw/ppc/e500.c          | 10 ++++++++++
> hw/ppc/mac_newworld.c  | 10 ++++++++++
> hw/ppc/mac_oldworld.c  | 10 ++++++++++
> hw/ppc/pegasos.c       |  5 +++++
> hw/ppc/pnv.c           | 20 ++++++++++++++++----
> hw/ppc/ppc440_bamboo.c |  4 ++++
> hw/ppc/prep.c          | 10 ++++++++++
> hw/ppc/sam460ex.c      |  5 +++++
> hw/ppc/spapr.c         |  8 ++++++++
> hw/ppc/virtex_ml507.c  |  9 +++++++++

but unless I missed something all these call it with error_fatal so the 
check added should never be reached therefore should not be needed.

Regards,
BALATON Zoltan


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

* Re: [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers
  2026-03-10 18:27 ` [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers Trieu Huynh
  2026-03-10 18:45   ` BALATON Zoltan
@ 2026-03-10 19:02   ` Aditya Gupta
  2026-03-10 19:10     ` Trieu Huynh
  2026-03-10 19:12     ` Aditya Gupta
  1 sibling, 2 replies; 15+ messages in thread
From: Aditya Gupta @ 2026-03-10 19:02 UTC (permalink / raw)
  To: Trieu Huynh, qemu-devel
  Cc: Richard Henderson, Helge Deller, Thomas Huth, Laurent Vivier,
	Edgar E. Iglesias, BALATON Zoltan, Bernhard Beschow,
	Mark Cave-Ayland, Nicholas Piggin, Glenn Miles,
	Hervé Poussineau, Harsh Prateek Bora, qemu-ppc


On 10/03/26 23:57, Trieu Huynh wrote:
> From: Trieu Huynh <vikingtc4@gmail.com>
>
> Check return value of load_image_targphys() and return early on
> failure instead of continuing with invalid state.
> - Use ret < 0 to handle negative return value.
> - No functional changes.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
> Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
>
> <...snip...>
>   
> diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
> index 1513575b8f..aecffb211b 100644
> --- a/hw/ppc/pnv.c
> +++ b/hw/ppc/pnv.c
> @@ -1068,14 +1068,21 @@ static void pnv_init(MachineState *machine)
>           exit(1);
>       }
>   
> -    load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
> -                        &error_fatal);
> +    if (load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
> +                        &error_fatal) < 0) {
> +        error_report("Could not load OPAL firmware '%s'", fw_filename);
> +        exit(1);
> +    }
>       g_free(fw_filename);
>   
>       /* load kernel */
>       if (machine->kernel_filename) {
> -        load_image_targphys(machine->kernel_filename,
> -                            KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, &error_fatal);
> +        if (load_image_targphys(machine->kernel_filename,
> +                        KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, &error_fatal) < 0) {
> +            error_report("Could not load kernel '%s'",
> +                         machine->kernel_filename);
> +            exit(1);
> +        }
>       }
>   
>       /* load initrd */
> @@ -1084,6 +1091,11 @@ static void pnv_init(MachineState *machine)
>           pnv->initrd_size = load_image_targphys(machine->initrd_filename,
>                                                  pnv->initrd_base,
>                                                  INITRD_MAX_SIZE, &error_fatal);
> +        if (pnv->initrd_size < 0) {
> +            error_report("Could not load initrd '%s'",
> +                         machine->initrd_filename);
> +            exit(1);
> +        }
>       }
>   
>       /* load dtb if passed */
>

Thanks for the patch, but as balaton said, atleast in this case, the 
condition is not needed since it's have error_fatal.

Previously the if checks you added used to there, these were recently 
changed to not have the conditions,
by this patch from vishal:

     commit cd274e83d50ba52ede62d2a8ea0f0ae7cb1ef469
     Author: Vishal Chourasia <vishalc@linux.ibm.com>
     Date:   Fri Oct 24 18:36:03 2025 +0530

     hw/ppc: Pass error_fatal to load_image_targphys()

     Pass error_fatal to load_image_targphys() calls in ppc machine 
initialization
     to capture detailed error information when loading firmware, kernel,
     and initrd images.

Thanks,

- Aditya G




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

* Re: [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers
  2026-03-10 19:02   ` Aditya Gupta
@ 2026-03-10 19:10     ` Trieu Huynh
  2026-03-10 19:12     ` Aditya Gupta
  1 sibling, 0 replies; 15+ messages in thread
From: Trieu Huynh @ 2026-03-10 19:10 UTC (permalink / raw)
  To: Aditya Gupta
  Cc: qemu-devel, Richard Henderson, Helge Deller, Thomas Huth,
	Laurent Vivier, Edgar E. Iglesias, BALATON Zoltan,
	Bernhard Beschow, Mark Cave-Ayland, Nicholas Piggin, Glenn Miles,
	Hervé Poussineau, Harsh Prateek Bora, qemu-ppc

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

Sorry, I was missed on that change.
Pls ignore patch 1/4.

BRs,

Vào 02:02 AM T.4, 11 Th3, 2026 Aditya Gupta <adityag@linux.ibm.com> đã viết:

>
> On 10/03/26 23:57, Trieu Huynh wrote:
> > From: Trieu Huynh <vikingtc4@gmail.com>
> >
> > Check return value of load_image_targphys() and return early on
> > failure instead of continuing with invalid state.
> > - Use ret < 0 to handle negative return value.
> > - No functional changes.
> >
> > Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
> > Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
> >
> > <...snip...>
> >
> > diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
> > index 1513575b8f..aecffb211b 100644
> > --- a/hw/ppc/pnv.c
> > +++ b/hw/ppc/pnv.c
> > @@ -1068,14 +1068,21 @@ static void pnv_init(MachineState *machine)
> >           exit(1);
> >       }
> >
> > -    load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
> > -                        &error_fatal);
> > +    if (load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
> > +                        &error_fatal) < 0) {
> > +        error_report("Could not load OPAL firmware '%s'", fw_filename);
> > +        exit(1);
> > +    }
> >       g_free(fw_filename);
> >
> >       /* load kernel */
> >       if (machine->kernel_filename) {
> > -        load_image_targphys(machine->kernel_filename,
> > -                            KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE,
> &error_fatal);
> > +        if (load_image_targphys(machine->kernel_filename,
> > +                        KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE,
> &error_fatal) < 0) {
> > +            error_report("Could not load kernel '%s'",
> > +                         machine->kernel_filename);
> > +            exit(1);
> > +        }
> >       }
> >
> >       /* load initrd */
> > @@ -1084,6 +1091,11 @@ static void pnv_init(MachineState *machine)
> >           pnv->initrd_size =
> load_image_targphys(machine->initrd_filename,
> >                                                  pnv->initrd_base,
> >                                                  INITRD_MAX_SIZE,
> &error_fatal);
> > +        if (pnv->initrd_size < 0) {
> > +            error_report("Could not load initrd '%s'",
> > +                         machine->initrd_filename);
> > +            exit(1);
> > +        }
> >       }
> >
> >       /* load dtb if passed */
> >
>
> Thanks for the patch, but as balaton said, atleast in this case, the
> condition is not needed since it's have error_fatal.
>
> Previously the if checks you added used to there, these were recently
> changed to not have the conditions,
> by this patch from vishal:
>
>      commit cd274e83d50ba52ede62d2a8ea0f0ae7cb1ef469
>      Author: Vishal Chourasia <vishalc@linux.ibm.com>
>      Date:   Fri Oct 24 18:36:03 2025 +0530
>
>      hw/ppc: Pass error_fatal to load_image_targphys()
>
>      Pass error_fatal to load_image_targphys() calls in ppc machine
> initialization
>      to capture detailed error information when loading firmware, kernel,
>      and initrd images.
>
> Thanks,
>
> - Aditya G
>
>
>

[-- Attachment #2: Type: text/html, Size: 4606 bytes --]

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

* Re: [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers
  2026-03-10 19:02   ` Aditya Gupta
  2026-03-10 19:10     ` Trieu Huynh
@ 2026-03-10 19:12     ` Aditya Gupta
  1 sibling, 0 replies; 15+ messages in thread
From: Aditya Gupta @ 2026-03-10 19:12 UTC (permalink / raw)
  To: Trieu Huynh, qemu-devel
  Cc: Richard Henderson, Helge Deller, Thomas Huth, Laurent Vivier,
	Edgar E. Iglesias, BALATON Zoltan, Bernhard Beschow,
	Mark Cave-Ayland, Nicholas Piggin, Glenn Miles,
	Hervé Poussineau, Harsh Prateek Bora, qemu-ppc


On 11/03/26 00:32, Aditya Gupta wrote:
>
> On 10/03/26 23:57, Trieu Huynh wrote:
>> From: Trieu Huynh <vikingtc4@gmail.com>
>>
>> Check return value of load_image_targphys() and return early on
>> failure instead of continuing with invalid state.
>> - Use ret < 0 to handle negative return value.
>> - No functional changes.
>>
>> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
>> Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
>>
>> <...snip...>
>>   diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
>> index 1513575b8f..aecffb211b 100644
>> --- a/hw/ppc/pnv.c
>> +++ b/hw/ppc/pnv.c
>> @@ -1068,14 +1068,21 @@ static void pnv_init(MachineState *machine)
>>           exit(1);
>>       }
>>   -    load_image_targphys(fw_filename, pnv->fw_load_addr, FW_MAX_SIZE,
>> -                        &error_fatal);
>> +    if (load_image_targphys(fw_filename, pnv->fw_load_addr, 
>> FW_MAX_SIZE,
>> +                        &error_fatal) < 0) {
>> +        error_report("Could not load OPAL firmware '%s'", fw_filename);
>> +        exit(1);
>> +    }
>>       g_free(fw_filename);
>>         /* load kernel */
>>       if (machine->kernel_filename) {
>> -        load_image_targphys(machine->kernel_filename,
>> -                            KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, 
>> &error_fatal);
>> +        if (load_image_targphys(machine->kernel_filename,
>> +                        KERNEL_LOAD_ADDR, KERNEL_MAX_SIZE, 
>> &error_fatal) < 0) {
>> +            error_report("Could not load kernel '%s'",
>> +                         machine->kernel_filename);
>> +            exit(1);
>> +        }
>>       }
>>         /* load initrd */
>> @@ -1084,6 +1091,11 @@ static void pnv_init(MachineState *machine)
>>           pnv->initrd_size = 
>> load_image_targphys(machine->initrd_filename,
>> pnv->initrd_base,
>> INITRD_MAX_SIZE, &error_fatal);
>> +        if (pnv->initrd_size < 0) {
>> +            error_report("Could not load initrd '%s'",
>> +                         machine->initrd_filename);
>> +            exit(1);
>> +        }
>>       }
>>         /* load dtb if passed */
>>
>
> Thanks for the patch, but as balaton said, atleast in this case, the 
> condition is not needed since it's have error_fatal.
>
> Previously the if checks you added used to there, these were recently 
> changed to not have the conditions,
> by this patch from vishal:
>
>     commit cd274e83d50ba52ede62d2a8ea0f0ae7cb1ef469
>     Author: Vishal Chourasia <vishalc@linux.ibm.com>
>     Date:   Fri Oct 24 18:36:03 2025 +0530
>
>     hw/ppc: Pass error_fatal to load_image_targphys()
>
>     Pass error_fatal to load_image_targphys() calls in ppc machine 
> initialization
>     to capture detailed error information when loading firmware, kernel,
>     and initrd images.


To add to this, it might be better to pass an error object to 
load_image_targphys, or error_fatal
if we are exiting in the if condition. That gives more details for why 
the load failed.

The NULL arguments were added in this: 
https://lore.kernel.org/qemu-devel/20251024130556.1942835-6-vishalc@linux.ibm.com/

That was because it was intended to not affect other machines, and hence 
it stayed with default
behavior of ignoring return value of load_image_targphys

This can be changed to use similar to PPC's approach to use error_fatal, 
if that's intended.



Thanks,
- Aditya G



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

* Re: [PATCH 4/4] hw/pci/msix: fix error handling for msix_init callers
  2026-03-10 18:28 ` [PATCH 4/4] hw/pci/msix: fix error handling for msix_init callers Trieu Huynh
@ 2026-03-11  5:52   ` Akihiko Odaki
  0 siblings, 0 replies; 15+ messages in thread
From: Akihiko Odaki @ 2026-03-11  5:52 UTC (permalink / raw)
  To: Trieu Huynh, qemu-devel
  Cc: Sriram Yagnaraman, Jason Wang, Jiri Pirko, Michael S. Tsirkin,
	Marcel Apfelbaum, Paolo Bonzini, Fam Zheng, Hannes Reinecke,
	qemu-block

On 2026/03/11 3:28, Trieu Huynh wrote:
> From: Trieu Huynh <vikingtc4@gmail.com>
> 
> Check return value of msix_init() and return early on
> failure instead of continuing with invalid state.
> - Use ret < 0 to handle negative return value.
> - No functional changes.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
> Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
> ---
>   hw/net/igbvf.c         |  2 +-
>   hw/net/rocker/rocker.c |  2 +-
>   hw/pci/msix.c          |  2 +-
>   hw/scsi/megasas.c      | 16 +++++++++++-----
>   hw/usb/hcd-xhci-pci.c  | 17 ++++++++++++-----
>   5 files changed, 26 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/net/igbvf.c b/hw/net/igbvf.c
> index 48d56e43ac..9a165c7063 100644
> --- a/hw/net/igbvf.c
> +++ b/hw/net/igbvf.c
> @@ -260,7 +260,7 @@ static void igbvf_pci_realize(PCIDevice *dev, Error **errp)
>   
>       ret = msix_init(dev, IGBVF_MSIX_VEC_NUM, &s->msix, IGBVF_MSIX_BAR_IDX, 0,
>           &s->msix, IGBVF_MSIX_BAR_IDX, 0x2000, 0x70, errp);
> -    if (ret) {
> +    if (ret < 0) {
>           return;
>       }
>   
> diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
> index 4a7056bd45..910dce901b 100644
> --- a/hw/net/rocker/rocker.c
> +++ b/hw/net/rocker/rocker.c
> @@ -1228,7 +1228,7 @@ static int rocker_msix_init(Rocker *r, Error **errp)
>                       &r->msix_bar,
>                       ROCKER_PCI_MSIX_BAR_IDX, ROCKER_PCI_MSIX_PBA_OFFSET,
>                       0, errp);
> -    if (err) {
> +    if (err < 0) {
>           return err;
>       }
>   
> diff --git a/hw/pci/msix.c b/hw/pci/msix.c
> index b35476d057..1b23eaf100 100644
> --- a/hw/pci/msix.c
> +++ b/hw/pci/msix.c
> @@ -432,7 +432,7 @@ int msix_init_exclusive_bar(PCIDevice *dev, uint32_t nentries,
>                       0, &dev->msix_exclusive_bar,
>                       bar_nr, bar_pba_offset,
>                       0, errp);
> -    if (ret) {
> +    if (ret < 0) {
>           return ret;
>       }
>   
> diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
> index f62e420a91..90d397374e 100644
> --- a/hw/scsi/megasas.c
> +++ b/hw/scsi/megasas.c
> @@ -2380,11 +2380,17 @@ static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
>       memory_region_init_io(&s->queue_io, OBJECT(s), &megasas_queue_ops, s,
>                             "megasas-queue", 0x40000);
>   
> -    if (megasas_use_msix(s) &&
> -        msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000,
> -                  &s->mmio_io, b->mmio_bar, 0x3800, 0x68, NULL)) {
> -        /* TODO: check msix_init's error, and should fail on msix=on */
> -        s->msix = ON_OFF_AUTO_OFF;
> +    if (megasas_use_msix(s)) {
> +        ret = msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000,
> +                        &s->mmio_io, b->mmio_bar, 0x3800, 0x68, NULL);
> +
> +        if (ret < 0) {
> +            if (s->msix == ON_OFF_AUTO_ON) {
> +                error_setg(errp, "MSI-X initialization failed");

msix_init() has the errp parameter so let's use it.

Regards,
Akihiko Odaki

> +                return;
> +            }
> +            s->msix = ON_OFF_AUTO_OFF;
> +        }
>       }
>   
>       if (pci_is_express(dev)) {
> diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c
> index aa570506fc..7bd4425b34 100644
> --- a/hw/usb/hcd-xhci-pci.c
> +++ b/hw/usb/hcd-xhci-pci.c
> @@ -173,11 +173,18 @@ static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp)
>       }
>   
>       if (s->msix != ON_OFF_AUTO_OFF) {
> -        /* TODO check for errors, and should fail when msix=on */
> -        msix_init(dev, s->xhci.numintrs,
> -                  &s->xhci.mem, 0, OFF_MSIX_TABLE,
> -                  &s->xhci.mem, 0, OFF_MSIX_PBA,
> -                  0x90, NULL);
> +        ret = msix_init(dev, s->xhci.numintrs,
> +                        &s->xhci.mem, 0, OFF_MSIX_TABLE,
> +                        &s->xhci.mem, 0, OFF_MSIX_PBA,
> +                        0x90, NULL);
> +
> +        if (ret < 0) {
> +            if (s->msix == ON_OFF_AUTO_ON) {
> +                error_setg(errp, "MSI-X initialization failed");
> +                return;
> +            }
> +            s->msix = ON_OFF_AUTO_OFF;
> +        }
>       }
>       s->xhci.as = pci_get_address_space(dev);
>   }



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

* Re: [PATCH 2/4] hw/core/loader: fix error handling for get_image_size callers
  2026-03-10 18:27 ` [PATCH 2/4] hw/core/loader: fix error handling for get_image_size callers Trieu Huynh
@ 2026-03-11  8:13   ` Clément Chigot
  0 siblings, 0 replies; 15+ messages in thread
From: Clément Chigot @ 2026-03-11  8:13 UTC (permalink / raw)
  To: Trieu Huynh
  Cc: qemu-devel, Corey Minyard, Frederic Konrad, Mark Cave-Ayland,
	Artyom Tarasenko

On Tue, Mar 10, 2026 at 7:32 PM Trieu Huynh <vikingtc4@gmail.com> wrote:
>
> From: Trieu Huynh <vikingtc4@gmail.com>
>
> Check return value of get_image_size() and return early on
> failure instead of continuing with invalid state.
> - Use ret < 0 to handle negative return value.
> - No functional changes.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
> Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
> ---
>  hw/ipmi/ipmi_bmc_sim.c | 2 ++
>  hw/sparc/leon3.c       | 5 +++++
>  2 files changed, 7 insertions(+)
>
> diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
> index 012e2ee4fe..fd875491f5 100644
> --- a/hw/ipmi/ipmi_bmc_sim.c
> +++ b/hw/ipmi/ipmi_bmc_sim.c
> @@ -2561,6 +2561,8 @@ static void ipmi_fru_init(IPMIFru *fru)
>              g_free(fru->data);
>              fru->data = NULL;
>          }
> +    } else {
> +        error_report("Could not get file size '%s'", fru->filename);
>      }
>
>  out:
> diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
> index 9147d56bd4..c821dfd3bb 100644
> --- a/hw/sparc/leon3.c
> +++ b/hw/sparc/leon3.c
> @@ -354,6 +354,11 @@ static void leon3_generic_hw_init(MachineState *machine)
>      } else {
>          bios_size = -1;
>      }
> +    if (bios_size < 0) {
> +        error_report("could not found or failed to get file size: '%s'",
> +                     filename);
> +        exit(1);
> +    }

This makes the bios mandatory for leon3 machines, which has not been
the case until now. I think we should introduce `-bios none`, as in
RiscV to allow such possibility.

>      if (bios_size > prom_size) {
>          error_report("could not load prom '%s': file too big", filename);
> --
> 2.43.0
>


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

* Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers
  2026-03-10 18:27 ` [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers Trieu Huynh
@ 2026-03-11 10:47   ` Anthony Krowiak
  2026-03-11 16:01   ` Jag Raman
  1 sibling, 0 replies; 15+ messages in thread
From: Anthony Krowiak @ 2026-03-11 10:47 UTC (permalink / raw)
  To: Trieu Huynh, qemu-devel
  Cc: Maciej S. Szmigiero, Elena Ufimtseva, Jagannathan Raman,
	Thomas Huth, Alex Williamson, Cédric Le Goater, Halil Pasic,
	Jason Herne, Eric Farman, Matthew Rosato, Michael S. Tsirkin,
	Stefano Garzarella, qemu-s390x



On 3/10/26 2:27 PM, Trieu Huynh wrote:
> From: Trieu Huynh <vikingtc4@gmail.com>
>
> Check return value of event_notifier_init() and return early on
> failure instead of continuing with invalid state.
> - Use ret < 0 to handle negative return value.
> - No functional changes.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
> Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
> ---
>   hw/hyperv/hyperv.c     |  4 ++--
>   hw/hyperv/vmbus.c      |  4 ++--
>   hw/remote/proxy.c      | 15 +++++++++++++--
>   hw/vfio/ap.c           |  2 +-
>   hw/vfio/ccw.c          |  2 +-
>   hw/vfio/pci-quirks.c   |  2 +-
>   hw/vfio/pci.c          |  2 +-
>   hw/virtio/vhost-vdpa.c |  4 ++--
>   8 files changed, 23 insertions(+), 12 deletions(-)
>
> diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c
> index 27e323a819..aa278b179e 100644
> --- a/hw/hyperv/hyperv.c
> +++ b/hw/hyperv/hyperv.c
> @@ -439,7 +439,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
>           sint_route->staged_msg->cb_data = cb_data;
>   
>           r = event_notifier_init(ack_notifier, false);
> -        if (r) {
> +        if (r < 0) {
>               goto cleanup_err_sint;
>           }
>           event_notifier_set_handler(ack_notifier, sint_ack_handler);
> @@ -453,7 +453,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
>   
>       /* We need to setup a GSI for this SintRoute */
>       r = event_notifier_init(&sint_route->sint_set_notifier, false);
> -    if (r) {
> +    if (r < 0) {
>           goto cleanup_err_sint;
>       }
>   
> diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
> index c5bab5d245..2f0d2a03d8 100644
> --- a/hw/hyperv/vmbus.c
> +++ b/hw/hyperv/vmbus.c
> @@ -1425,7 +1425,7 @@ static void open_channel(VMBusChannel *chan)
>           goto put_gpadl;
>       }
>   
> -    if (event_notifier_init(&chan->notifier, 0)) {
> +    if (event_notifier_init(&chan->notifier, 0) < 0) {
>           goto put_gpadl;
>       }
>   
> @@ -2416,7 +2416,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
>       }
>   
>       ret = event_notifier_init(&vmbus->notifier, 0);
> -    if (ret != 0) {
> +    if (ret < 0) {
>           error_setg(errp, "event notifier failed to init with %d", ret);
>           goto remove_msg_handler;
>       }
> diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c
> index 5081d67e7f..e91566509f 100644
> --- a/hw/remote/proxy.c
> +++ b/hw/remote/proxy.c
> @@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev)
>       PCIDevice *pci_dev = PCI_DEVICE(dev);
>       MPQemuMsg msg;
>       Error *local_err = NULL;
> +    int ret = 0;
>   
> -    event_notifier_init(&dev->intr, 0);
> -    event_notifier_init(&dev->resample, 0);
> +    ret = event_notifier_init(&dev->intr, 0);
> +    if (ret < 0) {
> +        error_report("Failed to init intr notifier: %s", strerror(-ret));
> +        return;
> +    }
> +
> +    ret = event_notifier_init(&dev->resample, 0);
> +    if (ret < 0) {
> +        error_report("Failed to init resample notifier: %s", strerror(-ret));
> +        event_notifier_cleanup(&dev->intr);
> +        return;
> +    }
>   
>       memset(&msg, 0, sizeof(MPQemuMsg));
>       msg.cmd = MPQEMU_CMD_SET_IRQFD;
> diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
> index e58a0169af..5c8f305653 100644
> --- a/hw/vfio/ap.c
> +++ b/hw/vfio/ap.c
> @@ -180,7 +180,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
>           return false;
>       }
>   
> -    if (event_notifier_init(notifier, 0)) {
> +    if (event_notifier_init(notifier, 0) < 0) {

Acked-by:  Anthony Krowiak <akrowiak@linux.ibm.com>

>           error_setg_errno(errp, errno,
>                            "vfio: Unable to init event notifier for irq (%d)",
>                            irq);
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> index 2251facb35..ce9c014e6a 100644
> --- a/hw/vfio/ccw.c
> +++ b/hw/vfio/ccw.c
> @@ -418,7 +418,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
>           return false;
>       }
>   
> -    if (event_notifier_init(notifier, 0)) {
> +    if (event_notifier_init(notifier, 0) < 0) {
>           error_setg_errno(errp, errno,
>                            "vfio: Unable to init event notifier for irq (%d)",
>                            irq);
> diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
> index 7b907b9360..66e02b15a4 100644
> --- a/hw/vfio/pci-quirks.c
> +++ b/hw/vfio/pci-quirks.c
> @@ -318,7 +318,7 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevice *vdev,
>   
>       ioeventfd = g_malloc0(sizeof(*ioeventfd));
>   
> -    if (event_notifier_init(&ioeventfd->e, 0)) {
> +    if (event_notifier_init(&ioeventfd->e, 0) < 0) {
>           g_free(ioeventfd);
>           return NULL;
>       }
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index c89f3fbea3..29bf6511b3 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -70,7 +70,7 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e,
>       }
>   
>       ret = event_notifier_init(e, 0);
> -    if (ret) {
> +    if (ret < 0) {
>           error_setg_errno(errp, -ret, "vfio_notifier_init %s failed", name);
>           return false;
>       }
> diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
> index 2f8f11df86..9c7634e243 100644
> --- a/hw/virtio/vhost-vdpa.c
> +++ b/hw/virtio/vhost-vdpa.c
> @@ -1075,13 +1075,13 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,
>       int r;
>   
>       r = event_notifier_init(&svq->hdev_kick, 0);
> -    if (r != 0) {
> +    if (r < 0) {
>           error_setg_errno(errp, -r, "Couldn't create kick event notifier");
>           goto err_init_hdev_kick;
>       }
>   
>       r = event_notifier_init(&svq->hdev_call, 0);
> -    if (r != 0) {
> +    if (r < 0) {
>           error_setg_errno(errp, -r, "Couldn't create call event notifier");
>           goto err_init_hdev_call;
>       }



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

* Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers
  2026-03-10 18:27 ` [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers Trieu Huynh
  2026-03-11 10:47   ` Anthony Krowiak
@ 2026-03-11 16:01   ` Jag Raman
  2026-03-11 16:09     ` Deprecate Multi-process QEMU (Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers) Cédric Le Goater
  1 sibling, 1 reply; 15+ messages in thread
From: Jag Raman @ 2026-03-11 16:01 UTC (permalink / raw)
  To: Trieu Huynh
  Cc: qemu-devel@nongnu.org, Maciej Szmigiero, Elena Ufimtseva,
	Thomas Huth, Alex Williamson, Cédric Le Goater, Tony Krowiak,
	Halil Pasic, Jason Herne, Eric Farman, Matthew Rosato,
	Michael S. Tsirkin, Stefano Garzarella, qemu-s390x@nongnu.org



> On Mar 10, 2026, at 2:27 PM, Trieu Huynh <vikingtc4@gmail.com> wrote:
> 
> From: Trieu Huynh <vikingtc4@gmail.com>
> 
> Check return value of event_notifier_init() and return early on
> failure instead of continuing with invalid state.
> - Use ret < 0 to handle negative return value.
> - No functional changes.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
> Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>

LGTM

Reviewed-by: Jagannathan Raman <jag.raman@oracle.com>

Please see note below.

> ---
> hw/hyperv/hyperv.c     |  4 ++--
> hw/hyperv/vmbus.c      |  4 ++--
> hw/remote/proxy.c      | 15 +++++++++++++--
> hw/vfio/ap.c           |  2 +-
> hw/vfio/ccw.c          |  2 +-
> hw/vfio/pci-quirks.c   |  2 +-
> hw/vfio/pci.c          |  2 +-
> hw/virtio/vhost-vdpa.c |  4 ++--
> 8 files changed, 23 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c
> index 27e323a819..aa278b179e 100644
> --- a/hw/hyperv/hyperv.c
> +++ b/hw/hyperv/hyperv.c
> @@ -439,7 +439,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
>         sint_route->staged_msg->cb_data = cb_data;
> 
>         r = event_notifier_init(ack_notifier, false);
> -        if (r) {
> +        if (r < 0) {
>             goto cleanup_err_sint;
>         }
>         event_notifier_set_handler(ack_notifier, sint_ack_handler);
> @@ -453,7 +453,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
> 
>     /* We need to setup a GSI for this SintRoute */
>     r = event_notifier_init(&sint_route->sint_set_notifier, false);
> -    if (r) {
> +    if (r < 0) {
>         goto cleanup_err_sint;
>     }
> 
> diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c
> index c5bab5d245..2f0d2a03d8 100644
> --- a/hw/hyperv/vmbus.c
> +++ b/hw/hyperv/vmbus.c
> @@ -1425,7 +1425,7 @@ static void open_channel(VMBusChannel *chan)
>         goto put_gpadl;
>     }
> 
> -    if (event_notifier_init(&chan->notifier, 0)) {
> +    if (event_notifier_init(&chan->notifier, 0) < 0) {
>         goto put_gpadl;
>     }
> 
> @@ -2416,7 +2416,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
>     }
> 
>     ret = event_notifier_init(&vmbus->notifier, 0);
> -    if (ret != 0) {
> +    if (ret < 0) {
>         error_setg(errp, "event notifier failed to init with %d", ret);
>         goto remove_msg_handler;
>     }
> diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c
> index 5081d67e7f..e91566509f 100644
> --- a/hw/remote/proxy.c
> +++ b/hw/remote/proxy.c
> @@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev)
>     PCIDevice *pci_dev = PCI_DEVICE(dev);
>     MPQemuMsg msg;
>     Error *local_err = NULL;
> +    int ret = 0;
> 
> -    event_notifier_init(&dev->intr, 0);
> -    event_notifier_init(&dev->resample, 0);
> +    ret = event_notifier_init(&dev->intr, 0);
> +    if (ret < 0) {
> +        error_report("Failed to init intr notifier: %s", strerror(-ret));

setup_irqfd() should ideally propagate the error up the stack.
But hw/remote/proxy.c is planned for removal as it is superseded
by vfio-user, so we don’t need to do it.

Thanks,
Jag

> +        return;
> +    }
> +
> +    ret = event_notifier_init(&dev->resample, 0);
> +    if (ret < 0) {
> +        error_report("Failed to init resample notifier: %s", strerror(-ret));
> +        event_notifier_cleanup(&dev->intr);
> +        return;
> +    }
> 
>     memset(&msg, 0, sizeof(MPQemuMsg));
>     msg.cmd = MPQEMU_CMD_SET_IRQFD;
> diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
> index e58a0169af..5c8f305653 100644
> --- a/hw/vfio/ap.c
> +++ b/hw/vfio/ap.c
> @@ -180,7 +180,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
>         return false;
>     }
> 
> -    if (event_notifier_init(notifier, 0)) {
> +    if (event_notifier_init(notifier, 0) < 0) {
>         error_setg_errno(errp, errno,
>                          "vfio: Unable to init event notifier for irq (%d)",
>                          irq);
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> index 2251facb35..ce9c014e6a 100644
> --- a/hw/vfio/ccw.c
> +++ b/hw/vfio/ccw.c
> @@ -418,7 +418,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
>         return false;
>     }
> 
> -    if (event_notifier_init(notifier, 0)) {
> +    if (event_notifier_init(notifier, 0) < 0) {
>         error_setg_errno(errp, errno,
>                          "vfio: Unable to init event notifier for irq (%d)",
>                          irq);
> diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
> index 7b907b9360..66e02b15a4 100644
> --- a/hw/vfio/pci-quirks.c
> +++ b/hw/vfio/pci-quirks.c
> @@ -318,7 +318,7 @@ static VFIOIOEventFD *vfio_ioeventfd_init(VFIOPCIDevice *vdev,
> 
>     ioeventfd = g_malloc0(sizeof(*ioeventfd));
> 
> -    if (event_notifier_init(&ioeventfd->e, 0)) {
> +    if (event_notifier_init(&ioeventfd->e, 0) < 0) {
>         g_free(ioeventfd);
>         return NULL;
>     }
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index c89f3fbea3..29bf6511b3 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -70,7 +70,7 @@ static bool vfio_notifier_init(VFIOPCIDevice *vdev, EventNotifier *e,
>     }
> 
>     ret = event_notifier_init(e, 0);
> -    if (ret) {
> +    if (ret < 0) {
>         error_setg_errno(errp, -ret, "vfio_notifier_init %s failed", name);
>         return false;
>     }
> diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
> index 2f8f11df86..9c7634e243 100644
> --- a/hw/virtio/vhost-vdpa.c
> +++ b/hw/virtio/vhost-vdpa.c
> @@ -1075,13 +1075,13 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,
>     int r;
> 
>     r = event_notifier_init(&svq->hdev_kick, 0);
> -    if (r != 0) {
> +    if (r < 0) {
>         error_setg_errno(errp, -r, "Couldn't create kick event notifier");
>         goto err_init_hdev_kick;
>     }
> 
>     r = event_notifier_init(&svq->hdev_call, 0);
> -    if (r != 0) {
> +    if (r < 0) {
>         error_setg_errno(errp, -r, "Couldn't create call event notifier");
>         goto err_init_hdev_call;
>     }
> -- 
> 2.43.0
> 


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

* Deprecate Multi-process QEMU (Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers)
  2026-03-11 16:01   ` Jag Raman
@ 2026-03-11 16:09     ` Cédric Le Goater
  2026-03-11 16:15       ` Jag Raman
  0 siblings, 1 reply; 15+ messages in thread
From: Cédric Le Goater @ 2026-03-11 16:09 UTC (permalink / raw)
  To: Jag Raman, Trieu Huynh
  Cc: qemu-devel@nongnu.org, Maciej Szmigiero, Elena Ufimtseva,
	Thomas Huth, Alex Williamson, Tony Krowiak, Halil Pasic,
	Jason Herne, Eric Farman, Matthew Rosato, Michael S. Tsirkin,
	Stefano Garzarella, qemu-s390x@nongnu.org, John Levon

Hello Jag,

+ John

>> diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c
>> index 5081d67e7f..e91566509f 100644
>> --- a/hw/remote/proxy.c
>> +++ b/hw/remote/proxy.c
>> @@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev)
>>      PCIDevice *pci_dev = PCI_DEVICE(dev);
>>      MPQemuMsg msg;
>>      Error *local_err = NULL;
>> +    int ret = 0;
>>
>> -    event_notifier_init(&dev->intr, 0);
>> -    event_notifier_init(&dev->resample, 0);
>> +    ret = event_notifier_init(&dev->intr, 0);
>> +    if (ret < 0) {
>> +        error_report("Failed to init intr notifier: %s", strerror(-ret));
> 
> setup_irqfd() should ideally propagate the error up the stack.
> But hw/remote/proxy.c is planned for removal as it is superseded
> by vfio-user, so we don’t need to do it.

In that case, could you please send an update of docs/about/deprecated.rst
to deprecate Multi-process QEMU ?

Thanks,

C.



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

* Re: Deprecate Multi-process QEMU (Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers)
  2026-03-11 16:09     ` Deprecate Multi-process QEMU (Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers) Cédric Le Goater
@ 2026-03-11 16:15       ` Jag Raman
  0 siblings, 0 replies; 15+ messages in thread
From: Jag Raman @ 2026-03-11 16:15 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Trieu Huynh, qemu-devel@nongnu.org, Maciej Szmigiero,
	Elena Ufimtseva, Thomas Huth, Alex Williamson, Tony Krowiak,
	Halil Pasic, Jason Herne, Eric Farman, Matthew Rosato,
	Michael S. Tsirkin, Stefano Garzarella, qemu-s390x@nongnu.org,
	John Levon



> On Mar 11, 2026, at 12:09 PM, Cédric Le Goater <clg@redhat.com> wrote:
> 
> Hello Jag,
> 
> + John
> 
>>> diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c
>>> index 5081d67e7f..e91566509f 100644
>>> --- a/hw/remote/proxy.c
>>> +++ b/hw/remote/proxy.c
>>> @@ -52,9 +52,20 @@ static void setup_irqfd(PCIProxyDev *dev)
>>>     PCIDevice *pci_dev = PCI_DEVICE(dev);
>>>     MPQemuMsg msg;
>>>     Error *local_err = NULL;
>>> +    int ret = 0;
>>> 
>>> -    event_notifier_init(&dev->intr, 0);
>>> -    event_notifier_init(&dev->resample, 0);
>>> +    ret = event_notifier_init(&dev->intr, 0);
>>> +    if (ret < 0) {
>>> +        error_report("Failed to init intr notifier: %s", strerror(-ret));
>> setup_irqfd() should ideally propagate the error up the stack.
>> But hw/remote/proxy.c is planned for removal as it is superseded
>> by vfio-user, so we don’t need to do it.
> 
> In that case, could you please send an update of docs/about/deprecated.rst
> to deprecate Multi-process QEMU ?

Sounds good, Cedric. Will do.

> 
> Thanks,
> 
> C.
> 


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

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

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 18:27 [PATCH 0/4] Fix error handling for callers of Trieu Huynh
2026-03-10 18:27 ` [PATCH 1/4] hw/core/loader: fix error handling for load_image_targphys callers Trieu Huynh
2026-03-10 18:45   ` BALATON Zoltan
2026-03-10 19:02   ` Aditya Gupta
2026-03-10 19:10     ` Trieu Huynh
2026-03-10 19:12     ` Aditya Gupta
2026-03-10 18:27 ` [PATCH 2/4] hw/core/loader: fix error handling for get_image_size callers Trieu Huynh
2026-03-11  8:13   ` Clément Chigot
2026-03-10 18:27 ` [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers Trieu Huynh
2026-03-11 10:47   ` Anthony Krowiak
2026-03-11 16:01   ` Jag Raman
2026-03-11 16:09     ` Deprecate Multi-process QEMU (Re: [PATCH 3/4] util/event_notifier: fix error handling for event_notifier_init callers) Cédric Le Goater
2026-03-11 16:15       ` Jag Raman
2026-03-10 18:28 ` [PATCH 4/4] hw/pci/msix: fix error handling for msix_init callers Trieu Huynh
2026-03-11  5:52   ` Akihiko Odaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox