Commit 193982c6 authored by Alexey Kardashevskiy's avatar Alexey Kardashevskiy Committed by Michael S. Tsirkin
Browse files

pci: Only unmap bus_master_enabled_region if was added previously



Normally pci_init_bus_master() would be called either via
bus->machine_done.notify or directly from do_pci_register_device().

However if a device's realize() failed, pci_init_bus_master() is not
called, and do_pci_unregister_device() fails on
memory_region_del_subregion() as it was not mapped.

This adds a check that subregion was mapped before unmapping it.

Fixes: c53598ed ("pci: Add missing drop of bus master AS reference")
Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarMarcel Apfelbaum <marcel@redhat.com>
Acked-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Tested-by: default avatarJohn Snow <jsnow@redhat.com>
parent 87cc4c61
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -869,8 +869,10 @@ static void do_pci_unregister_device(PCIDevice *pci_dev)
    pci_dev->bus->devices[pci_dev->devfn] = NULL;
    pci_config_free(pci_dev);

    if (memory_region_is_mapped(&pci_dev->bus_master_enable_region)) {
        memory_region_del_subregion(&pci_dev->bus_master_container_region,
                                    &pci_dev->bus_master_enable_region);
    }
    address_space_destroy(&pci_dev->bus_master_as);
}