[PATCH 3/5] hw/core: Pass errp to load_image_targphys_as()

Vishal Chourasia posted 5 patches 4 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Peter Maydell <peter.maydell@linaro.org>, Antony Pavlov <antonynpavlov@gmail.com>, Rob Herring <robh@kernel.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Alistair Francis <alistair@alistair23.me>, "Alex Bennée" <alex.bennee@linaro.org>, Helge Deller <deller@gmx.de>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Corey Minyard <minyard@acm.org>, Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Thomas Huth <huth@tuxfamily.org>, Laurent Vivier <laurent@vivier.eu>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Paul Burton <paulburton@kernel.org>, Aleksandar Rikalo <arikalo@gmail.com>, Huacai Chen <chenhuacai@kernel.org>, "Hervé Poussineau" <hpoussin@reactos.org>, Aurelien Jarno <aurelien@aurel32.net>, Stafford Horne <shorne@gmail.com>, BALATON Zoltan <balaton@eik.bme.hu>, Bernhard Beschow <shentey@gmail.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Nicholas Piggin <npiggin@gmail.com>, Aditya Gupta <adityag@linux.ibm.com>, Glenn Miles <milesg@linux.ibm.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <yoshinori.sato@nifty.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Jared Rossi <jrossi@linux.ibm.com>, Zhuoying Cai <zycai@linux.ibm.com>, Halil Pasic <pasic@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Magnus Damm <magnus.damm@gmail.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, "Clément Chigot" <chigot@adacore.com>, Frederic Konrad <konrad.frederic@yahoo.fr>, Artyom Tarasenko <atar4qemu@gmail.com>, Max Filippov <jcmvbkbc@gmail.com>, David Gibson <david@gibson.dropbear.id.au>
[PATCH 3/5] hw/core: Pass errp to load_image_targphys_as()
Posted by Vishal Chourasia 4 weeks ago
Pass errp to load_image_targphys_as() in generic-loader and
guest-loader to capture detailed error information from the
loader functions.

Use error_prepend() instead of error_setg() to preserve the
underlying error details while adding context about which image
failed to load.

Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com>
---
 hw/core/generic-loader.c | 4 ++--
 hw/core/guest-loader.c   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index 6689847c33..433efb7387 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -149,13 +149,13 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
         if (size < 0 || s->force_raw) {
             /* Default to the maximum size being the machine's ram size */
             size = load_image_targphys_as(s->file, s->addr,
-                    current_machine->ram_size, as, NULL);
+                    current_machine->ram_size, as, errp);
         } else {
             s->addr = entry;
         }
 
         if (size < 0) {
-            error_setg(errp, "Cannot load specified image %s", s->file);
+            error_prepend(errp, "Cannot load specified image %s: ", s->file);
             return;
         }
     }
diff --git a/hw/core/guest-loader.c b/hw/core/guest-loader.c
index 59f325ad9c..618455e556 100644
--- a/hw/core/guest-loader.c
+++ b/hw/core/guest-loader.c
@@ -101,9 +101,9 @@ static void guest_loader_realize(DeviceState *dev, Error **errp)
 
     /* Default to the maximum size being the machine's ram size */
     size = load_image_targphys_as(file, s->addr, current_machine->ram_size,
-                                  NULL, NULL);
+                                  NULL, errp);
     if (size < 0) {
-        error_setg(errp, "Cannot load specified image %s", file);
+        error_prepend(errp, "Cannot load specified image %s: ", file);
         return;
     }
 
-- 
2.51.0
Re: [PATCH 3/5] hw/core: Pass errp to load_image_targphys_as()
Posted by Alistair Francis 4 weeks ago
On Fri, Oct 17, 2025 at 3:41 AM Vishal Chourasia <vishalc@linux.ibm.com> wrote:
>
> Pass errp to load_image_targphys_as() in generic-loader and
> guest-loader to capture detailed error information from the
> loader functions.
>
> Use error_prepend() instead of error_setg() to preserve the
> underlying error details while adding context about which image
> failed to load.
>
> Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/core/generic-loader.c | 4 ++--
>  hw/core/guest-loader.c   | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
> index 6689847c33..433efb7387 100644
> --- a/hw/core/generic-loader.c
> +++ b/hw/core/generic-loader.c
> @@ -149,13 +149,13 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
>          if (size < 0 || s->force_raw) {
>              /* Default to the maximum size being the machine's ram size */
>              size = load_image_targphys_as(s->file, s->addr,
> -                    current_machine->ram_size, as, NULL);
> +                    current_machine->ram_size, as, errp);
>          } else {
>              s->addr = entry;
>          }
>
>          if (size < 0) {
> -            error_setg(errp, "Cannot load specified image %s", s->file);
> +            error_prepend(errp, "Cannot load specified image %s: ", s->file);
>              return;
>          }
>      }
> diff --git a/hw/core/guest-loader.c b/hw/core/guest-loader.c
> index 59f325ad9c..618455e556 100644
> --- a/hw/core/guest-loader.c
> +++ b/hw/core/guest-loader.c
> @@ -101,9 +101,9 @@ static void guest_loader_realize(DeviceState *dev, Error **errp)
>
>      /* Default to the maximum size being the machine's ram size */
>      size = load_image_targphys_as(file, s->addr, current_machine->ram_size,
> -                                  NULL, NULL);
> +                                  NULL, errp);
>      if (size < 0) {
> -        error_setg(errp, "Cannot load specified image %s", file);
> +        error_prepend(errp, "Cannot load specified image %s: ", file);
>          return;
>      }
>
> --
> 2.51.0
>
>
Re: [PATCH 3/5] hw/core: Pass errp to load_image_targphys_as()
Posted by Vishal Chourasia 4 weeks ago
Thanks Alistair for the review.

On 17/10/25 04:29, Alistair Francis wrote:
> On Fri, Oct 17, 2025 at 3:41 AM Vishal Chourasia <vishalc@linux.ibm.com> wrote:
>> Pass errp to load_image_targphys_as() in generic-loader and
>> guest-loader to capture detailed error information from the
>> loader functions.
>>
>> Use error_prepend() instead of error_setg() to preserve the
>> underlying error details while adding context about which image
>> failed to load.
>>
>> Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com>
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

I have one more change to be added to this patch.

diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index 433efb7387..c69c857ed4 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -155,7 +155,12 @@ static void generic_loader_realize(DeviceState 
*dev, Error **errp)
          }

          if (size < 0) {
-            error_prepend(errp, "Cannot load specified image %s: ", 
s->file);
+            const char *msg = "Cannot load specified image %s: ";
+            if (*errp) {
+                error_prepend(errp, msg, s->file);
+            } else {
+                error_setg(errp, msg, s->file);
+            }
              return;
          }
      }

Similar change has to be done in guest-loader.c
I will include it in v4.

>
> Alistair
>
>> ---
>>   hw/core/generic-loader.c | 4 ++--
>>   hw/core/guest-loader.c   | 4 ++--
>>   2 files changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
>> index 6689847c33..433efb7387 100644
>> --- a/hw/core/generic-loader.c
>> +++ b/hw/core/generic-loader.c
>> @@ -149,13 +149,13 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
>>           if (size < 0 || s->force_raw) {
>>               /* Default to the maximum size being the machine's ram size */
>>               size = load_image_targphys_as(s->file, s->addr,
>> -                    current_machine->ram_size, as, NULL);
>> +                    current_machine->ram_size, as, errp);
>>           } else {
>>               s->addr = entry;
>>           }
>>
>>           if (size < 0) {
>> -            error_setg(errp, "Cannot load specified image %s", s->file);
>> +            error_prepend(errp, "Cannot load specified image %s: ", s->file);
>>               return;
>>           }
>>       }
>> diff --git a/hw/core/guest-loader.c b/hw/core/guest-loader.c
>> index 59f325ad9c..618455e556 100644
>> --- a/hw/core/guest-loader.c
>> +++ b/hw/core/guest-loader.c
>> @@ -101,9 +101,9 @@ static void guest_loader_realize(DeviceState *dev, Error **errp)
>>
>>       /* Default to the maximum size being the machine's ram size */
>>       size = load_image_targphys_as(file, s->addr, current_machine->ram_size,
>> -                                  NULL, NULL);
>> +                                  NULL, errp);
>>       if (size < 0) {
>> -        error_setg(errp, "Cannot load specified image %s", file);
>> +        error_prepend(errp, "Cannot load specified image %s: ", file);
>>           return;
>>       }
>>
>> --
>> 2.51.0
>>
>>