@@ -893,6 +893,7 @@ static int disable_device(struct acpiphp_slot *slot)
pdev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));
if (!pdev)
goto err_exit;
+ pci_dev_put(pdev);
list_for_each_entry(func, &slot->funcs, sibling) {
if (func->bridge) {
@@ -902,9 +903,20 @@ static int disable_device(struct acpiphp_slot *slot)
func->bridge = NULL;
}
- pdev = pci_get_slot(slot->bridge->pci_bus,
- PCI_DEVFN(slot->device, func->function));
- if (pdev) {
+ while (1) {
+ /* pci_bus_sem is used to protect bus->devices list,
+ it may cause invalid memory access if threads
+ modify bus->devices list concurrently. */
+ down_read(&pci_bus_sem);
+ list_for_each_entry(pdev, &bus->devices, bus_list)
+ if (PCI_SLOT(pdev->devfn) == slot->device) {
+ pci_dev_get(pdev);
+ break;
+ }
+ up_read(&pci_bus_sem);
+
+ if (!pdev || PCI_SLOT(pdev->devfn) != slot->device)
+ break;
pci_stop_bus_device(pdev);
if (pdev->subordinate) {
disable_bridges(pdev->subordinate);