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

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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to