Skip to content

Commit 58d9a38

Browse files
Yinghai Lubjorn-helgaas
authored andcommitted
PCI: Skip attaching driver in device_add()
We want to add PCI devices to the device tree as early as possible but delay attaching drivers. device_add() adds a device to the device hierarchy and (via device_attach()) attaches a matching driver and calls its .probe() method. We want to separate adding the device to the hierarchy from attaching the driver. This patch does that by adding "match_driver" in struct pci_dev. When false, we return failure from pci_bus_match(), which makes device_attach() believe there's no matching driver. Later, we set "match_driver = true" and call device_attach() again, which now attaches the driver and calls its .probe() method. [bhelgaas: changelog, explicitly init dev->match_driver, fold device_attach() call into pci_bus_add_device()] Signed-off-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent d59f53b commit 58d9a38

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

drivers/pci/bus.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,15 @@ int pci_bus_add_device(struct pci_dev *dev)
177177
if (retval)
178178
return retval;
179179

180+
dev->match_driver = false;
180181
retval = device_add(&dev->dev);
181182
if (retval)
182183
return retval;
183184

185+
dev->match_driver = true;
186+
retval = device_attach(&dev->dev);
187+
WARN_ON(retval < 0);
188+
184189
dev->is_added = 1;
185190
pci_proc_attach_device(dev);
186191
pci_create_sysfs_dev_files(dev);

drivers/pci/pci-driver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,9 +1186,13 @@ pci_dev_driver(const struct pci_dev *dev)
11861186
static int pci_bus_match(struct device *dev, struct device_driver *drv)
11871187
{
11881188
struct pci_dev *pci_dev = to_pci_dev(dev);
1189-
struct pci_driver *pci_drv = to_pci_driver(drv);
1189+
struct pci_driver *pci_drv;
11901190
const struct pci_device_id *found_id;
11911191

1192+
if (!pci_dev->match_driver)
1193+
return 0;
1194+
1195+
pci_drv = to_pci_driver(drv);
11921196
found_id = pci_match_device(pci_drv, pci_dev);
11931197
if (found_id)
11941198
return 1;

include/linux/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ struct pci_dev {
286286
unsigned int irq;
287287
struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
288288

289+
bool match_driver; /* Skip attaching driver */
289290
/* These fields are used by common fixups */
290291
unsigned int transparent:1; /* Transparent PCI bridge */
291292
unsigned int multifunction:1;/* Part of multi-function device */

0 commit comments

Comments
 (0)