diff mbox

[RFC,v1,18/22] PCI/acpiphp: use PCI bus lock to avoid race conditions

Message ID 1344355862-2726-19-git-send-email-jiang.liu@huawei.com
State Not Applicable
Headers show

Commit Message

Jiang Liu Aug. 7, 2012, 4:10 p.m. UTC
From: Jiang Liu <liuj97@gmail.com>

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@gmail.com>
---
 drivers/pci/hotplug/acpiphp_glue.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
diff mbox

Patch

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;