From: Mario Casquero <[email protected]> Updates vfio_pci_load_rom() to use Error API for error propagation instead of error_report(), improving error handling consistency.
Signed-off-by: Mario Casquero <[email protected]> Reviewed-by: Cédric Le Goater <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Link: https://lore.kernel.org/qemu-devel/[email protected] Signed-off-by: Cédric Le Goater <[email protected]> --- hw/vfio/pci.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c7f163399f8fbcc4ff70819a0d67879eb26980f9..e6d1adfd3655ce3c1baf8977c82223d23af9b770 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1028,7 +1028,7 @@ static void vfio_update_msi(VFIOPCIDevice *vdev) } } -static bool vfio_pci_load_rom(VFIOPCIDevice *vdev) +static bool vfio_pci_load_rom(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev = &vdev->vbasedev; struct vfio_region_info *reg_info = NULL; @@ -1041,7 +1041,7 @@ static bool vfio_pci_load_rom(VFIOPCIDevice *vdev) ®_info); if (ret != 0) { - error_report("vfio: Error getting ROM info: %s", strerror(-ret)); + error_setg_errno(errp, -ret, "vfio: Error getting ROM info"); return false; } @@ -1053,10 +1053,13 @@ static bool vfio_pci_load_rom(VFIOPCIDevice *vdev) vdev->rom_offset = reg_info->offset; if (!vdev->rom_size) { - error_report("vfio-pci: Cannot read device rom at %s", vbasedev->name); - error_printf("Device option ROM contents are probably invalid " - "(check dmesg).\nSkip option ROM probe with rombar=0, " - "or load from file with romfile=\n"); + vdev->rom_size = 0; + vdev->rom_offset = 0; + error_setg(errp, "vfio-pci: Device ROM size is zero at %s", + vbasedev->name); + error_append_hint(errp, "Device option ROM contents are probably " + "invalid (check dmesg).\nSkip option ROM probe " + "with rombar=0, or load from file with romfile=\n"); return false; } @@ -1077,10 +1080,12 @@ static bool vfio_pci_load_rom(VFIOPCIDevice *vdev) if (bytes == -EINTR || bytes == -EAGAIN) { continue; } - error_report("vfio: Error reading device ROM: %s", - strreaderror(bytes)); - - break; + error_setg_errno(errp, -bytes, "vfio: Error reading device ROM"); + g_free(vdev->rom); + vdev->rom = NULL; + vdev->rom_size = 0; + vdev->rom_offset = 0; + return false; } } @@ -1148,7 +1153,12 @@ static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size) /* Load the ROM lazily when the guest tries to read it */ if (unlikely(!vdev->rom && !vdev->rom_read_failed)) { - vdev->rom_read_failed = !vfio_pci_load_rom(vdev); + Error *local_err = NULL; + + vdev->rom_read_failed = !vfio_pci_load_rom(vdev, &local_err); + if (vdev->rom_read_failed) { + error_report_err(local_err); + } } memcpy(&val, vdev->rom + addr, -- 2.54.0
