From: Daniel Paziyski <[email protected]> When a PCI device fails to be registered using do_pci_register_device, which takes the PCI device as one of its arguments, and returns the PCI device itself on success or null on failure, the acpi index is forcefully released using pci_unregister_acpi_index.
However, this causes a null pointer to be passed always on failure to pci_unregister_acpi_index. Instead, do not reassign pci_dev from the return value of do_pci_register_device, just check it. Cc: [email protected] Resolves: Coverity CID 1689947 Fixes: 432ea8cc7d27 ("pcie_sriov: register user created virtual function before realizing it") Signed-off-by: Daniel Paziyski <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Message-ID: <[email protected]> (cherry picked from commit 7ecad9ed2e1c7fc7076cb23186c0e3b3317b6c4e) (Fixes: 11ecc538c5b2 in 11.1.x) Signed-off-by: Michael Tokarev <[email protected]> diff --git a/hw/pci/pci.c b/hw/pci/pci.c index d4187293b1f..51713451cb3 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2310,10 +2310,8 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp) pci_dev->cap_present |= QEMU_PCIE_CAP_CXL; } - pci_dev = do_pci_register_device(pci_dev, - object_get_typename(OBJECT(qdev)), - pci_dev->devfn, errp); - if (pci_dev == NULL) { + if (!do_pci_register_device(pci_dev, object_get_typename(OBJECT(qdev)), + pci_dev->devfn, errp)) { pci_unregister_acpi_index(pci_dev); return; } -- 2.47.3
