public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 05/27] hw/core/loader: fix error handling for load_image_targphys callers
Date: Mon, 23 Mar 2026 17:51:56 +0100	[thread overview]
Message-ID: <20260323165218.96607-6-philmd@linaro.org> (raw)
In-Reply-To: <20260323165218.96607-1-philmd@linaro.org>

From: Trieu Huynh <vikingtc4@gmail.com>

Use QEMU's Error API to handle load_image_targphys() failures
consistently across callers.

- Use &error_fatal for callers that previously passed NULL, ensuring
the process exits early on failure instead of continuing in an invalid
state.
- No functional changes.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20260318141415.8538-2-vikingtc4@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/alpha/dp264.c     |  2 +-
 hw/hppa/machine.c    |  2 +-
 hw/m68k/next-cube.c  | 11 +++++++++--
 hw/m68k/q800.c       |  2 +-
 hw/m68k/virt.c       |  2 +-
 hw/microblaze/boot.c |  3 ++-
 6 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index 98219f04569..2ab3c147471 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -190,7 +190,7 @@ 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);
+                                ram_size - initrd_base, &error_fatal);
 
             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 318ebfeee46..3663bac53bd 100644
--- a/hw/hppa/machine.c
+++ b/hw/hppa/machine.c
@@ -527,7 +527,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
             }
 
             load_image_targphys(initrd_filename, initrd_base, initrd_size,
-                                NULL);
+                                &error_fatal);
             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 26177c7b867..4bfe5bcf569 100644
--- a/hw/m68k/next-cube.c
+++ b/hw/m68k/next-cube.c
@@ -1326,9 +1326,16 @@ 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) {
+    Error *local_err = NULL;
+    if (load_image_targphys(bios_name, 0x01000000, 0x20000, &local_err) < 8) {
         if (!qtest_enabled()) {
-            error_report("Failed to load firmware '%s'.", bios_name);
+            if (local_err) {
+                error_report_err(local_err);
+            } else {
+                error_report("Firmware image '%s' is too short.", bios_name);
+            }
+        } else {
+            error_free(local_err);
         }
     } else {
         uint8_t *ptr;
diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index ded531394e6..c0d78eb7d71 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -633,7 +633,7 @@ 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);
+                                ram_size - initrd_base, &error_fatal);
             BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base,
                       initrd_size);
         } else {
diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index e67900c727d..ffe6e234155 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -292,7 +292,7 @@ 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);
+                                ram_size - initrd_base, &error_fatal);
             BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base,
                       initrd_size);
         } else {
diff --git a/hw/microblaze/boot.c b/hw/microblaze/boot.c
index a6f9ebab90c..4ad5ffd34bd 100644
--- a/hw/microblaze/boot.c
+++ b/hw/microblaze/boot.c
@@ -38,6 +38,7 @@
 #include "hw/core/loader.h"
 #include "elf.h"
 #include "qemu/cutils.h"
+#include "qapi/error.h"
 
 #include "boot.h"
 
@@ -171,7 +172,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, bool is_little_endian,
         /* Not an ELF image nor an u-boot image, try a RAW image.  */
         if (kernel_size < 0) {
             kernel_size = load_image_targphys(kernel_filename, ddr_base,
-                                              ramsize, NULL);
+                                              ramsize, &error_fatal);
             boot_info.bootstrap_pc = ddr_base;
             high = (ddr_base + kernel_size + 3) & ~3;
         }
-- 
2.53.0



  parent reply	other threads:[~2026-03-23 16:53 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 16:51 [PULL 00/27] Misc HW patches for 2026-03-23 Philippe Mathieu-Daudé
2026-03-23 16:51 ` [PULL 01/27] hw/riscv: Mark RISC-V specific peripherals as little-endian Philippe Mathieu-Daudé
2026-03-23 16:51 ` [PULL 02/27] hw/cxl: Use HPA in cxl_cfmws_find_device() rather than offset in window Philippe Mathieu-Daudé
2026-03-23 16:51 ` [PULL 03/27] hw/char/virtio-console: clear dangling GLib event source tag Philippe Mathieu-Daudé
2026-03-23 16:51 ` [PULL 04/27] hw/i3c/dw-i3c: Fix uninitialized data use in short transfer Philippe Mathieu-Daudé
2026-03-23 16:51 ` Philippe Mathieu-Daudé [this message]
2026-03-23 16:51 ` [PULL 06/27] hw/core/loader: fix error handling for get_image_size callers Philippe Mathieu-Daudé
2026-03-23 16:51 ` [PULL 07/27] util/event_notifier: fix error handling for event_notifier_init callers Philippe Mathieu-Daudé
2026-03-23 16:51 ` [PULL 08/27] hw/pci/msix: fix error handling for msix_init callers Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 09/27] hw/i386/pc_sysfw: stub out x86_firmware_configure Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 10/27] hw/i386/hyperv: add stubs for synic enablement Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 11/27] hw/cxl: Respect Media Operation max ops discovery semantics Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 12/27] hw/cxl: Exclude Discovery from Media Operation Discovery output Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 13/27] backends/iommufd: report error when /dev/iommu is not available Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 14/27] hw/vfio/iommufd: report hint to user when vfio-dev/vfio*/dev is missing Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 15/27] hw/hyperv: Fix SynIC not initialized except on first vCPU Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 16/27] hw/usb/hcd-ohci: check for MPS=0 to avoid infinite loop Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 17/27] ati-vga: Fix colors when frame buffer endianness does not match host Philippe Mathieu-Daudé
2026-03-24 19:06   ` Peter Maydell
2026-03-24 20:21     ` BALATON Zoltan
2026-03-23 16:52 ` [PULL 18/27] ati-vga: Also switch mode on HW cursor enable bit change Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 19/27] ati-vga: Do not add crtc offset to src and dst data address Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 20/27] ati-vga: Avoid warnings about sign extension Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 21/27] ati-vga: Fix display updates in non-32 bit modes Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 22/27] ati-vga: Add work around for fuloong2e Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 23/27] ati-vga: Simplify pointer image handling Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 24/27] ati-vga: Make sure hardware cursor data is within vram Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 25/27] hw/net/ftgmac100: Improve DMA error handling Philippe Mathieu-Daudé
2026-03-24  8:03   ` Cédric Le Goater
2026-03-24 19:21     ` Philippe Mathieu-Daudé
2026-03-24 21:59       ` Cédric Le Goater
2026-03-23 16:52 ` [PULL 26/27] monitor: Correctly display virtual addresses while dumping memory Philippe Mathieu-Daudé
2026-03-23 16:52 ` [PULL 27/27] hw/hyperv: add QEMU_PACKED to uapi structs Philippe Mathieu-Daudé
2026-03-24 10:08 ` [PULL 00/27] Misc HW patches for 2026-03-23 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260323165218.96607-6-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox