From: Mario Casquero <[email protected]> When vfio_device_get_region_info() fails in vfio_pci_load_rom(), the function returns without setting vdev->rom_read_failed to true, and without allocating vdev->rom. This leaves vdev->rom as NULL.
Signed-off-by: Mario Casquero <[email protected]> Reviewed-by: Cédric Le Goater <[email protected]> Link: https://lore.kernel.org/qemu-devel/[email protected] Signed-off-by: Cédric Le Goater <[email protected]> --- hw/vfio/pci.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4d822b96b530c614671551589ce3584e9598f386..68ee3ce7dc254dd045ed2c1b21bebc53a4b4e3d6 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1028,7 +1028,7 @@ static void vfio_update_msi(VFIOPCIDevice *vdev) } } -static void vfio_pci_load_rom(VFIOPCIDevice *vdev) +static bool vfio_pci_load_rom(VFIOPCIDevice *vdev) { VFIODevice *vbasedev = &vdev->vbasedev; struct vfio_region_info *reg_info = NULL; @@ -1042,7 +1042,7 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev) if (ret != 0) { error_report("vfio: Error getting ROM info: %s", strerror(-ret)); - return; + return false; } trace_vfio_pci_load_rom(vbasedev->name, (unsigned long)reg_info->size, @@ -1053,12 +1053,11 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev) vdev->rom_offset = reg_info->offset; if (!vdev->rom_size) { - vdev->rom_read_failed = true; 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"); - return; + return false; } vdev->rom = g_malloc(size); @@ -1114,6 +1113,8 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev) data[6] = -csum; } } + + return true; } /* "Raw" read of underlying config space. */ @@ -1147,7 +1148,7 @@ 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)) { - vfio_pci_load_rom(vdev); + vdev->rom_read_failed = !vfio_pci_load_rom(vdev); } memcpy(&val, vdev->rom + addr, -- 2.54.0
