[v2,part,1,2/9] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev()

Submitted by Jiang Liu on May 13, 2013, 4:08 p.m.


Message ID 1368461313-4371-3-git-send-email-jiang.liu@huawei.com
State Superseded
Headers show

Commit Message

Jiang Liu May 13, 2013, 4:08 p.m.
From: Gu Zheng <guz.fnst@cn.fujitsu.com>

<marker to prevent gmail from removing below "From:">
From: Gu Zheng <guz.fnst@cn.fujitsu.com>

Now here we introduce a new interface to replace alloc_pci_dev():
	struct pci_dev *pci_alloc_dev(struct pci_bus *bus)

It take a "struct pci_bus *" argument, so we can alloc a pci device
on a target pci bus, and it acquire the reference of 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.

Jiang Liu <jiang.liu@huawei.com>
Minor code tweaks and change
__deprecated struct pci_dev * alloc_pci_dev(void);
struct pci_dev * __deprecated alloc_pci_dev(void);

This enhancement makes it safe to reference pci_dev->bus when holding
a reference on a pci_dev.

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
 drivers/pci/probe.c | 16 +++++++++++-----
 include/linux/pci.h |  3 ++-
 2 files changed, 13 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 43ece5d..4f0bc0a 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1201,18 +1201,24 @@  static void pci_release_bus_bridge_dev(struct device *dev)
-struct pci_dev *alloc_pci_dev(void)
+struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
 	struct pci_dev *dev;
 	dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
-	if (!dev)
-		return NULL;
-	INIT_LIST_HEAD(&dev->bus_list);
+	if (dev) {
+		INIT_LIST_HEAD(&dev->bus_list);
+		dev->bus = pci_bus_get(bus);
+	}
 	return dev;
+struct pci_dev *alloc_pci_dev(void)
+	return pci_alloc_dev(NULL);
 bool 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 f5e13f0..68beb11 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)
 	return dev;
-struct pci_dev *alloc_pci_dev(void);
+struct pci_dev *pci_alloc_dev(struct pci_bus *bus);
+struct pci_dev * __deprecated alloc_pci_dev(void);
 #define	to_pci_dev(n) container_of(n, struct pci_dev, dev)
 #define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)