aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGu Zheng <guz.fnst@cn.fujitsu.com>2013-05-25 09:48:30 -0400
committerBjorn Helgaas <bhelgaas@google.com>2013-05-27 18:23:28 -0400
commit3c6e6ae770f338ef3e54c5823c21063204f53537 (patch)
tree7460a7cdf07d4e2a734b9c39706b34ab85b6e05f
parentfe830ef62ac6d8814e27b7e2f632848694b0e5c7 (diff)
PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()
Here we introduce a new interface to replace alloc_pci_dev(): struct pci_dev *pci_alloc_dev(struct pci_bus *bus) It takes a "struct pci_bus *" argument, so we can alloc a PCI device on a target PCI bus, and it acquires a reference on the pci_bus. We use pci_alloc_dev(NULL) to simplify the old alloc_pci_dev(), and keep it for a while but mark it as __deprecated. Holding a reference to the pci_bus ensures that referencing pci_dev->bus is valid as long as the pci_dev is valid. [bhelgaas: keep existing "return error early" structure in pci_alloc_dev()] Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com> Signed-off-by: Jiang Liu <jiang.liu@huawei.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r--drivers/pci/probe.c9
-rw-r--r--include/linux/pci.h3
2 files changed, 10 insertions, 2 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 70f10fa3c1b2..d47ce1400c26 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1200,7 +1200,7 @@ static void pci_release_bus_bridge_dev(struct device *dev)
1200 kfree(bridge); 1200 kfree(bridge);
1201} 1201}
1202 1202
1203struct pci_dev *alloc_pci_dev(void) 1203struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
1204{ 1204{
1205 struct pci_dev *dev; 1205 struct pci_dev *dev;
1206 1206
@@ -1210,9 +1210,16 @@ struct pci_dev *alloc_pci_dev(void)
1210 1210
1211 INIT_LIST_HEAD(&dev->bus_list); 1211 INIT_LIST_HEAD(&dev->bus_list);
1212 dev->dev.type = &pci_dev_type; 1212 dev->dev.type = &pci_dev_type;
1213 dev->bus = pci_bus_get(bus);
1213 1214
1214 return dev; 1215 return dev;
1215} 1216}
1217EXPORT_SYMBOL(pci_alloc_dev);
1218
1219struct pci_dev *alloc_pci_dev(void)
1220{
1221 return pci_alloc_dev(NULL);
1222}
1216EXPORT_SYMBOL(alloc_pci_dev); 1223EXPORT_SYMBOL(alloc_pci_dev);
1217 1224
1218bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, 1225bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l,
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 7556c590ddfd..b0f4a8264118 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -364,7 +364,8 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
364 return dev; 364 return dev;
365} 365}
366 366
367struct pci_dev *alloc_pci_dev(void); 367struct pci_dev *pci_alloc_dev(struct pci_bus *bus);
368struct pci_dev * __deprecated alloc_pci_dev(void);
368 369
369#define to_pci_dev(n) container_of(n, struct pci_dev, dev) 370#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
370#define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) 371#define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)