Skip to content

Commit ea34511

Browse files
vliu-nutanixgregkh
authored andcommitted
driver core: Check drivers_autoprobe for all added devices
When a device is hot-plugged, the drivers_autoprobe sysfs attribute is not checked (at least for PCI devices). This means that drivers_autoprobe is not working as intended, e.g. hot-plugged PCI devices will still be autoprobed and bound to drivers even with drivers_autoprobe disabled. The problem likely started when device_add() was removed from pci_bus_add_device() in commit 4f53509 ("PCI: Put pci_dev in device tree as early as possible") which means that the check for drivers_autoprobe which used to happen in bus_probe_device() is no longer present (previously bus_add_device() calls bus_probe_device()). Conveniently, in commit 9170304 ("PCI: Allow built-in drivers to use async initial probing") device_attach() was replaced with device_initial_probe() which faciliates this change to push the check for drivers_autoprobe into device_initial_probe(). Make sure all devices check drivers_autoprobe by pushing the drivers_autoprobe check into device_initial_probe(). This will only affect devices on the PCI bus for now as device_initial_probe() is only called by pci_bus_add_device() and bus_probe_device(), but bus_probe_device() already checks for autoprobe, so callers of bus_probe_device() should not observe changes on autoprobing. Note also that pushing this check into device_initial_probe() rather than device_attach() makes it only affect automatic probing of drivers (e.g. when a device is hot-plugged), userspace can still choose to manually bind a driver by writing to drivers_probe sysfs attribute, even with autoprobe disabled. Any future callers of device_initial_probe() will respect the drivers_autoprobe sysfs attribute, which is the intended purpose of drivers_autoprobe. Signed-off-by: Vincent Liu <vincent.liu@nutanix.com> Link: https://patch.msgid.link/20251022120740.2476482-1-vincent.liu@nutanix.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ac1ab90 commit ea34511

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

drivers/base/bus.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,7 @@ void bus_probe_device(struct device *dev)
533533
if (!sp)
534534
return;
535535

536-
if (sp->drivers_autoprobe)
537-
device_initial_probe(dev);
536+
device_initial_probe(dev);
538537

539538
mutex_lock(&sp->mutex);
540539
list_for_each_entry(sif, &sp->interfaces, node)

drivers/base/dd.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,15 @@ EXPORT_SYMBOL_GPL(device_attach);
10771077

10781078
void device_initial_probe(struct device *dev)
10791079
{
1080-
__device_attach(dev, true);
1080+
struct subsys_private *sp = bus_to_subsys(dev->bus);
1081+
1082+
if (!sp)
1083+
return;
1084+
1085+
if (sp->drivers_autoprobe)
1086+
__device_attach(dev, true);
1087+
1088+
subsys_put(sp);
10811089
}
10821090

10831091
/*

0 commit comments

Comments
 (0)