summaryrefslogtreecommitdiffstats
path: root/hw
diff options
context:
space:
mode:
authorAlexey Kardashevskiy2017-03-31 06:47:11 +0200
committerMichael S. Tsirkin2017-04-04 17:32:25 +0200
commit193982c6f9424779b53a168fe32ebc30a776cbf1 (patch)
tree78d3f3f3cd8bff50a01c3052e45ec5b61b117efe /hw
parentMerge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (diff)
downloadqemu-193982c6f9424779b53a168fe32ebc30a776cbf1.tar.gz
qemu-193982c6f9424779b53a168fe32ebc30a776cbf1.tar.xz
qemu-193982c6f9424779b53a168fe32ebc30a776cbf1.zip
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: c53598ed18e4 ("pci: Add missing drop of bus master AS reference") Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Marcel Apfelbaum <marcel@redhat.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Tested-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/pci/pci.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index bd8043c460..259483b1c0 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -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);
- 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);
}