Thread (51 messages) 51 messages, 5 authors, 2012-09-26
STALE5042d

[RFC PATCH v1 17/22] PCI/pciehp: use PCI bus lock to avoid race conditions

From: Jiang Liu <hidden>
Date: 2012-08-07 16:21:10
Also in: lkml
Subsystem: pci subsystem, the rest · Maintainers: Bjorn Helgaas, Linus Torvalds

This patch uses PCI bus lock mechanism to avoid race conditions when doing
PCI device hotplug by pciehp driver.

Signed-off-by: Jiang Liu <redacted>
---
 drivers/pci/hotplug/pciehp_pci.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c
index 09cecaf..9536a9e 100644
--- a/drivers/pci/hotplug/pciehp_pci.c
+++ b/drivers/pci/hotplug/pciehp_pci.c
@@ -42,18 +42,25 @@ int pciehp_configure_device(struct slot *p_slot)
 	int num, fn;
 	struct controller *ctrl = p_slot->ctrl;
 
+	if (pci_bus_lock_states(parent, PCI_BUS_STATE_WORKING) < 0) {
+		ctrl_dbg(ctrl, "Port has been removed\n");
+		return -EINVAL;
+	}
+
 	dev = pci_get_slot(parent, PCI_DEVFN(0, 0));
 	if (dev) {
 		ctrl_err(ctrl, "Device %s already exists "
 			 "at %04x:%02x:00, cannot hot-add\n", pci_name(dev),
 			 pci_domain_nr(parent), parent->number);
 		pci_dev_put(dev);
+		pci_bus_unlock(parent);
 		return -EINVAL;
 	}
 
 	num = pci_scan_slot(parent, PCI_DEVFN(0, 0));
 	if (num == 0) {
 		ctrl_err(ctrl, "No new device found\n");
+		pci_bus_unlock(parent);
 		return -ENODEV;
 	}
 
@@ -82,6 +89,7 @@ int pciehp_configure_device(struct slot *p_slot)
 	}
 
 	pci_bus_add_devices(parent);
+	pci_bus_unlock(parent);
 
 	return 0;
 }
@@ -96,6 +104,11 @@ int pciehp_unconfigure_device(struct slot *p_slot)
 	u16 command;
 	struct controller *ctrl = p_slot->ctrl;
 
+	if (pci_bus_lock_states(parent, PCI_BUS_STATE_WORKING) < 0) {
+		ctrl_dbg(ctrl, "Port has been removed\n");
+		return -EINVAL;
+	}
+
 	ctrl_dbg(ctrl, "%s: domain:bus:dev = %04x:%02x:00\n",
 		 __func__, pci_domain_nr(parent), parent->number);
 	ret = pciehp_get_adapter_status(p_slot, &presence);
@@ -131,5 +144,7 @@ int pciehp_unconfigure_device(struct slot *p_slot)
 		pci_dev_put(temp);
 	}
 
+	pci_bus_unlock(parent);
+
 	return rc;
 }
-- 
1.7.9.5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help