hw/core/loader: fix error handling for load_image_targphys callers
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>
Trieu Huynh committed
Mar 18, 2026 at 23:14 UTC
b06bb02721a98d5b42b65868572c0edb4c783aa5
6 files changed
+15
-7
hw/alpha/dp264.c
+1
-1
@@ -190,7 +190,7 @@ static void clipper_init(MachineState *machine)
190
/* Put the initrd image as high in memory as possible. */
191
initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK;
192
load_image_targphys(initrd_filename, initrd_base,
193
- ram_size - initrd_base, NULL);
193
+ ram_size - initrd_base, &error_fatal);
194
195
address_space_stq_le(&address_space_memory, param_offset + 0x100,
196
initrd_base + 0xfffffc0000000000ULL,
hw/hppa/machine.c
+1
-1
@@ -527,7 +527,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
527
}
528
529
load_image_targphys(initrd_filename, initrd_base, initrd_size,
530
- NULL);
530
+ &error_fatal);
531
cpu[0]->env.initrd_base = initrd_base;
532
cpu[0]->env.initrd_end = initrd_base + initrd_size;
533
}
hw/m68k/next-cube.c
+9
-2
@@ -1326,9 +1326,16 @@ static void next_cube_init(MachineState *machine)
1326
memory_region_init_alias(&m->rom2, NULL, "next.rom2", &m->rom, 0x0,
1327
0x20000);
1328
memory_region_add_subregion(sysmem, 0x0, &m->rom2);
1329
- if (load_image_targphys(bios_name, 0x01000000, 0x20000, NULL) < 8) {
1329
+ Error *local_err = NULL;
1330
+ if (load_image_targphys(bios_name, 0x01000000, 0x20000, &local_err) < 8) {
1331
if (!qtest_enabled()) {
1331
- error_report("Failed to load firmware '%s'.", bios_name);
1332
+ if (local_err) {
1333
+ error_report_err(local_err);
1334
+ } else {
1335
+ error_report("Firmware image '%s' is too short.", bios_name);
1336
+ }
1337
+ } else {
1338
+ error_free(local_err);
1339
}
1340
} else {
1341
uint8_t *ptr;
hw/m68k/q800.c
+1
-1
@@ -633,7 +633,7 @@ static void q800_machine_init(MachineState *machine)
633
634
initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK;
635
load_image_targphys(initrd_filename, initrd_base,
636
- ram_size - initrd_base, NULL);
636
+ ram_size - initrd_base, &error_fatal);
637
BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base,
638
initrd_size);
639
} else {
hw/m68k/virt.c
+1
-1
@@ -292,7 +292,7 @@ static void virt_init(MachineState *machine)
292
293
initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK;
294
load_image_targphys(initrd_filename, initrd_base,
295
- ram_size - initrd_base, NULL);
295
+ ram_size - initrd_base, &error_fatal);
296
BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base,
297
initrd_size);
298
} else {
hw/microblaze/boot.c
+2
-1
@@ -38,6 +38,7 @@
38
#include "hw/core/loader.h"
39
#include "elf.h"
40
#include "qemu/cutils.h"
41
+#include "qapi/error.h"
42
43
#include "boot.h"
44
@@ -171,7 +172,7 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, bool is_little_endian,
172
/* Not an ELF image nor an u-boot image, try a RAW image. */
173
if (kernel_size < 0) {
174
kernel_size = load_image_targphys(kernel_filename, ddr_base,
174
- ramsize, NULL);
175
+ ramsize, &error_fatal);
176
boot_info.bootstrap_pc = ddr_base;
177
high = (ddr_base + kernel_size + 3) & ~3;
178
}