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]> (cherry picked from commit c822ecd806614fa24e7d3bd120a0f96b00d6d1a5) (Mjt: context fixup for v10.0.0-756-g2e27becf17b "vfio: consistently handle return value for helpers") Signed-off-by: Michael Tokarev <[email protected]> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 7f1532fbed9..b8f16d9c463 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -877,7 +877,7 @@ static void vfio_update_msi(VFIOPCIDevice *vdev) } } -static void vfio_pci_load_rom(VFIOPCIDevice *vdev) +static bool vfio_pci_load_rom(VFIOPCIDevice *vdev) { g_autofree struct vfio_region_info *reg_info = NULL; uint64_t size; @@ -887,7 +887,7 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev) if (vfio_get_region_info(&vdev->vbasedev, VFIO_PCI_ROM_REGION_INDEX, ®_info)) { error_report("vfio: Error getting ROM info: %m"); - return; + return false; } trace_vfio_pci_load_rom(vdev->vbasedev.name, (unsigned long)reg_info->size, @@ -898,13 +898,12 @@ 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", vdev->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); @@ -956,6 +955,8 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev) data[6] = -csum; } } + + return true; } static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size) @@ -971,7 +972,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.47.3
