pcmcia: Use global PCI rescan-remove locking
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 10 Jan 2014 14:25:34 +0000 (15:25 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 14 Jan 2014 19:14:25 +0000 (12:14 -0700)
Multiple race conditions are possible between the cardbus PCI device
addition and removal and the generic PCI bus rescan and device removal that
can be triggered via sysfs.

To avoid those race conditions make the cardbus code use global PCI
rescan-remove locking.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pcmcia/cardbus.c

index b2a98cdbd0d289dee032dfd71cd540ead129b8cc..8bde61952d20e4371b26cd80b31098cb392b67ea 100644 (file)
@@ -70,6 +70,8 @@ int __ref cb_alloc(struct pcmcia_socket *s)
        struct pci_dev *dev;
        unsigned int max, pass;
 
+       pci_lock_rescan_remove();
+
        s->functions = pci_scan_slot(bus, PCI_DEVFN(0, 0));
        pci_fixup_cardbus(bus);
 
@@ -93,6 +95,7 @@ int __ref cb_alloc(struct pcmcia_socket *s)
 
        pci_bus_add_devices(bus);
 
+       pci_unlock_rescan_remove();
        return 0;
 }
 
@@ -115,6 +118,10 @@ void cb_free(struct pcmcia_socket *s)
        if (!bus)
                return;
 
+       pci_lock_rescan_remove();
+
        list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list)
                pci_stop_and_remove_bus_device(dev);
+
+       pci_unlock_rescan_remove();
 }