lkml.org 
[lkml]   [2012]   [Aug]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v1 17/22] PCI/pciehp: use PCI bus lock to avoid race conditions
Date
This patch uses PCI bus lock mechanism to avoid race conditions when doing
PCI device hotplug by pciehp driver.

Signed-off-by: Jiang Liu <liuj97@gmail.com>
---
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


\
 
 \ /
  Last update: 2012-08-07 19:02    [W:1.130 / U:0.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site