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: c53598ed18e4 ("pci: Add missing drop of bus master AS reference")
Signed-off-by: Alexey Kardashevskiy <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Max Reitz <[email protected]>
Reviewed-by: Marcel Apfelbaum <[email protected]>
Acked-by: Paolo Bonzini <[email protected]>
Tested-by: John Snow <[email protected]>
pci_dev->bus->devices[pci_dev->devfn] = NULL;
pci_config_free(pci_dev);
- memory_region_del_subregion(&pci_dev->bus_master_container_region,
- &pci_dev->bus_master_enable_region);
+ 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);
}