]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
PCI: Hold pci_slot_mutex while searching bus->slots list
authorYijing Wang <wangyijing@huawei.com>
Fri, 17 Jul 2015 09:16:32 +0000 (17:16 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 30 Jul 2015 21:19:53 +0000 (16:19 -0500)
Previously, pci_setup_device() and similar functions searched the
pci_bus->slots list without any locking.  It was possible for another
thread to update the list while we searched it.

Add pci_dev_assign_slot() to search the list while holding pci_slot_mutex.

[bhelgaas: changelog, fold in CONFIG_SYSFS fix]
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
arch/powerpc/kernel/pci_of_scan.c
arch/sparc/kernel/pci.c
drivers/pci/probe.c
drivers/pci/slot.c
include/linux/pci.h

index 42e02a2d570bf70a63f0371b16a39c1aec24bbe3..5e2debfc6ce5c8e5a82b4c5e3ac186b4eddb7e6c 100644 (file)
@@ -126,7 +126,6 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
 {
        struct pci_dev *dev;
        const char *type;
-       struct pci_slot *slot;
 
        dev = pci_alloc_dev(bus);
        if (!dev)
@@ -145,10 +144,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
        dev->needs_freset = 0;          /* pcie fundamental reset required */
        set_pcie_port_type(dev);
 
-       list_for_each_entry(slot, &dev->bus->slots, list)
-               if (PCI_SLOT(dev->devfn) == slot->number)
-                       dev->slot = slot;
-
+       pci_dev_assign_slot(dev);
        dev->vendor = get_int_prop(node, "vendor-id", 0xffff);
        dev->device = get_int_prop(node, "device-id", 0xffff);
        dev->subsystem_vendor = get_int_prop(node, "subsystem-vendor-id", 0);
index c928bc64b4bac1b1c5eb88c71c348469796883c5..3a0e1a986bfe3cf89c9f3cb92ac04c056b0f86eb 100644 (file)
@@ -249,7 +249,6 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
                                         struct pci_bus *bus, int devfn)
 {
        struct dev_archdata *sd;
-       struct pci_slot *slot;
        struct platform_device *op;
        struct pci_dev *dev;
        const char *type;
@@ -290,10 +289,7 @@ static struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
        dev->multifunction = 0;         /* maybe a lie? */
        set_pcie_port_type(dev);
 
-       list_for_each_entry(slot, &dev->bus->slots, list)
-               if (PCI_SLOT(dev->devfn) == slot->number)
-                       dev->slot = slot;
-
+       pci_dev_assign_slot(dev);
        dev->vendor = of_getintprop_default(node, "vendor-id", 0xffff);
        dev->device = of_getintprop_default(node, "device-id", 0xffff);
        dev->subsystem_vendor =
index cefd636681b6418ce75376879dc26fe3891bc47d..2a9ce16cb374736f6ceb2d4d54eced71b2983b5b 100644 (file)
@@ -1133,7 +1133,6 @@ int pci_setup_device(struct pci_dev *dev)
 {
        u32 class;
        u8 hdr_type;
-       struct pci_slot *slot;
        int pos = 0;
        struct pci_bus_region region;
        struct resource *res;
@@ -1149,10 +1148,7 @@ int pci_setup_device(struct pci_dev *dev)
        dev->error_state = pci_channel_io_normal;
        set_pcie_port_type(dev);
 
-       list_for_each_entry(slot, &dev->bus->slots, list)
-               if (PCI_SLOT(dev->devfn) == slot->number)
-                       dev->slot = slot;
-
+       pci_dev_assign_slot(dev);
        /* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
           set this higher, assuming the system even supports it.  */
        dev->dma_mask = 0xffffffff;
index 4bd3fce93fa4e01a4eb0a1f28dbf0e8b05074e23..429d34c348b9fbddc373e22876ad4f5017788a8d 100644 (file)
@@ -194,6 +194,17 @@ static int rename_slot(struct pci_slot *slot, const char *name)
        return result;
 }
 
+void pci_dev_assign_slot(struct pci_dev *dev)
+{
+       struct pci_slot *slot;
+
+       mutex_lock(&pci_slot_mutex);
+       list_for_each_entry(slot, &dev->bus->slots, list)
+               if (PCI_SLOT(dev->devfn) == slot->number)
+                       dev->slot = slot;
+       mutex_unlock(&pci_slot_mutex);
+}
+
 static struct pci_slot *get_slot(struct pci_bus *parent, int slot_nr)
 {
        struct pci_slot *slot;
index aaee493174e29adc9ce6b38cf9566774e09fe121..b3ba7fef291603bd1304be8a147c4f92a5839b53 100644 (file)
@@ -798,6 +798,11 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
                                 const char *name,
                                 struct hotplug_slot *hotplug);
 void pci_destroy_slot(struct pci_slot *slot);
+#ifdef CONFIG_SYSFS
+void pci_dev_assign_slot(struct pci_dev *dev);
+#else
+static inline void pci_dev_assign_slot(struct pci_dev *dev) { }
+#endif
 int pci_scan_slot(struct pci_bus *bus, int devfn);
 struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn);
 void pci_device_add(struct pci_dev *dev, struct pci_bus *bus);