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 <[email protected]> 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 <[email protected]>
Reviewed-by: Alistair Francis <[email protected]>
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