From: Jiang Liu <liuj97@xxxxxxxxx> This patch uses PCI bus lock mechanism to avoid race conditions when doing PCI device/host bridge hotplug by acpiphp driver. Signed-off-by: Jiang Liu <liuj97@xxxxxxxxx> --- drivers/pci/hotplug/acpiphp_glue.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 73af337..0ea7ab1 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -800,11 +800,14 @@ static int __ref enable_device(struct acpiphp_slot *slot) if (slot->flags & SLOT_ENABLED) goto err_exit; + if (pci_bus_lock_states(bus, PCI_BUS_STATE_WORKING) < 0) + return -EINVAL; + num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0)); if (num == 0) { /* Maybe only part of funcs are added. */ dbg("No new device found\n"); - goto err_exit; + goto out_unlock; } max = acpiphp_max_busnr(bus); @@ -862,8 +865,10 @@ static int __ref enable_device(struct acpiphp_slot *slot) pci_dev_put(dev); } +out_unlock: + pci_bus_unlock(bus); - err_exit: +err_exit: return retval; } @@ -906,6 +911,9 @@ static int disable_device(struct acpiphp_slot *slot) struct pci_dev *pdev; struct pci_bus *bus = slot->bridge->pci_bus; + if (pci_bus_lock_states(bus, PCI_BUS_STATE_WORKING) < 0) + goto err_exit; + /* The slot will be enabled when func 0 is added, so check func 0 before disable the slot. */ pdev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0)); @@ -943,6 +951,7 @@ static int disable_device(struct acpiphp_slot *slot) } slot->flags &= (~SLOT_ENABLED); + pci_bus_unlock(bus); err_exit: return 0; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html