[Patch v9 5/6] core: Pass errp to load_image_targphys_as()

Vishal Chourasia posted 6 patches 3 days, 1 hour 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>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Halil Pasic <pasic@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Matthew Rosato <mjrosato@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>
There is a newer version of this series
[Patch v9 5/6] core: Pass errp to load_image_targphys_as()
Posted by Vishal Chourasia 3 days, 1 hour 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 | 7 ++++---
 hw/core/guest-loader.c   | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index 6689847c33..35d4e5f4ea 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -60,6 +60,7 @@ static void generic_loader_reset(void *opaque)
 
 static void generic_loader_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_GUARD();
     GenericLoaderState *s = GENERIC_LOADER(dev);
     hwaddr entry;
     ssize_t size = 0;
@@ -149,13 +150,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);
+        if (*errp) {
+            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..dcbe8e4520 100644
--- a/hw/core/guest-loader.c
+++ b/hw/core/guest-loader.c
@@ -81,6 +81,7 @@ static void loader_insert_platform_data(GuestLoaderState *s, int size,
 
 static void guest_loader_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_GUARD();
     GuestLoaderState *s = GUEST_LOADER(dev);
     char *file = s->kernel ? s->kernel : s->initrd;
     int size = 0;
@@ -101,9 +102,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);
-    if (size < 0) {
-        error_setg(errp, "Cannot load specified image %s", file);
+                                  NULL, errp);
+    if (*errp) {
+        error_prepend(errp, "Cannot load specified image %s: ", file);
         return;
     }
 
-- 
2.51.0
Re: [Patch v9 5/6] core: Pass errp to load_image_targphys_as()
Posted by Philippe Mathieu-Daudé 3 days, 1 hour ago
On 24/10/25 11:26, Vishal Chourasia 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>
> ---
>   hw/core/generic-loader.c | 7 ++++---
>   hw/core/guest-loader.c   | 7 ++++---
>   2 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
> index 6689847c33..35d4e5f4ea 100644
> --- a/hw/core/generic-loader.c
> +++ b/hw/core/generic-loader.c
> @@ -60,6 +60,7 @@ static void generic_loader_reset(void *opaque)
>   
>   static void generic_loader_realize(DeviceState *dev, Error **errp)
>   {
> +    ERRP_GUARD();
>       GenericLoaderState *s = GENERIC_LOADER(dev);
>       hwaddr entry;
>       ssize_t size = 0;
> @@ -149,13 +150,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);
> +        if (*errp) {

Again I'd keep the 'if (size < 0)' check to avoid *errp.

> +            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..dcbe8e4520 100644
> --- a/hw/core/guest-loader.c
> +++ b/hw/core/guest-loader.c
> @@ -81,6 +81,7 @@ static void loader_insert_platform_data(GuestLoaderState *s, int size,
>   
>   static void guest_loader_realize(DeviceState *dev, Error **errp)
>   {
> +    ERRP_GUARD();
>       GuestLoaderState *s = GUEST_LOADER(dev);
>       char *file = s->kernel ? s->kernel : s->initrd;
>       int size = 0;
> @@ -101,9 +102,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);
> -    if (size < 0) {
> -        error_setg(errp, "Cannot load specified image %s", file);
> +                                  NULL, errp);
> +    if (*errp) {

Ditto, otherwise:

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> +        error_prepend(errp, "Cannot load specified image %s: ", file);
>           return;
>       }
>