[PATCH v2 2/4] hw/core/loader: fix error handling for get_image_size callers

Trieu Huynh posted 4 patches 3 weeks, 6 days ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, "Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>, Corey Minyard <minyard@acm.org>, Thomas Huth <th.huth+qemu@posteo.eu>, Laurent Vivier <laurent@vivier.eu>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>, Jason Wang <jasowang@redhat.com>, Jiri Pirko <jiri@resnulli.us>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Elena Ufimtseva <elena.ufimtseva@oracle.com>, Jagannathan Raman <jag.raman@oracle.com>, Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>, "Clément Chigot" <chigot@adacore.com>, Frederic Konrad <konrad.frederic@yahoo.fr>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Tony Krowiak <akrowiak@linux.ibm.com>, Halil Pasic <pasic@linux.ibm.com>, Jason Herne <jjherne@linux.ibm.com>, Cornelia Huck <cohuck@redhat.com>, Eric Farman <farman@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>
There is a newer version of this series
[PATCH v2 2/4] hw/core/loader: fix error handling for get_image_size callers
Posted by Trieu Huynh 3 weeks, 6 days ago
From: Trieu Huynh <vikingtc4@gmail.com>

Check the return value of get_image_size() and report failures
for non-mandatory files such as BIOS or FRU images.

- Use ret < 0 to detect failures in getting image size.
- No functional changes.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>

---
v2:
- Keep error reporting as it is.
- Remove exit on error since it is not mandatory.
---
 hw/ipmi/ipmi_bmc_sim.c | 2 ++
 hw/sparc/leon3.c       | 4 ++++
 2 files changed, 6 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..122366829d 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -354,6 +354,10 @@ 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);
+    }
 
     if (bios_size > prom_size) {
         error_report("could not load prom '%s': file too big", filename);
-- 
2.43.0
Re: [PATCH v2 2/4] hw/core/loader: fix error handling for get_image_size callers
Posted by Clément Chigot 3 weeks, 5 days ago
On Wed, Mar 11, 2026 at 7:35 PM Trieu Huynh <vikingtc4@gmail.com> wrote:
>
> From: Trieu Huynh <vikingtc4@gmail.com>
>
> Check the return value of get_image_size() and report failures
> for non-mandatory files such as BIOS or FRU images.
>
> - Use ret < 0 to detect failures in getting image size.
> - No functional changes.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/413
> Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
>
> ---
> v2:
> - Keep error reporting as it is.
> - Remove exit on error since it is not mandatory.
> ---
>  hw/ipmi/ipmi_bmc_sim.c | 2 ++
>  hw/sparc/leon3.c       | 4 ++++
>  2 files changed, 6 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..122366829d 100644
> --- a/hw/sparc/leon3.c
> +++ b/hw/sparc/leon3.c
> @@ -354,6 +354,10 @@ 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);
> +    }

Honestly, I'm not sure what improvements that brings. This warning is
meaningless for Baremetal programs (launched without bios). Moreover,
an error handling is already there if "bios_size < 0" and -kernel is
not provided (just below).

A better approach could be to add support for "-bios none". With the
whole bios handling section (from "Allocate BIOS" up to
"g_free(filename);") could be wrapped under "if -bios != none".
But that differs slightly from your initial goal. So up to you.

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