[PATCH 08/17] driver core: Allow userspace to detect EPROBE_DEFER when using sysfs drivers_probe
From: Leon Romanovsky
Date: Thu Nov 05 2026 - 06:54:42 EST
From: Leon Romanovsky <leonro@xxxxxxxxxx>
commit b8c5cec23d5c ("Driver core: udev triggered device-<>driver
binding") introduced the concept of "Systems who want to control the
driver binding with udev" can use the drivers_probe sysfs to trigger a
driver bind based on the kernel's match list.
If attaching the driver is deferred before its probe callback runs,
userspace sees EINVAL and cannot tell it should try again, maybe after
loading other drivers.
Map that deferral to EAGAIN and add missed documentation for the
drivers_probe sysfs. A deferral requested by the probe callback itself
is still not reported.
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxx>
---
Documentation/ABI/testing/sysfs-bus-drivers-probe | 13 +++++++++++++
MAINTAINERS | 1 +
drivers/base/bus.c | 9 +++++++--
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-bus-drivers-probe b/Documentation/ABI/testing/sysfs-bus-drivers-probe
new file mode 100644
index 0000000000000..851c65b9331ae
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-drivers-probe
@@ -0,0 +1,13 @@
+What: /sys/bus/.../drivers_probe
+Date: February 2007
+Contact: driver-core@xxxxxxxxxxxxxxx
+Description:
+ (WO) Writing a device name requests driver attachment on this
+ bus, even when drivers_autoprobe is disabled. A successful
+ write does not guarantee that a driver bound. The device's
+ driver link reports the result.
+
+ EAGAIN means attachment was deferred before the driver's probe
+ callback, for example while a supplier or the device itself
+ is not ready. ENODEV means the device was not found. Other
+ attachment errors return EINVAL.
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315065d..b726344362b41 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8149,6 +8149,7 @@ M: Johan Hovold <johan@xxxxxxxxxx>
L: driver-core@xxxxxxxxxxxxxxx
S: Supported
T: git git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
+F: Documentation/ABI/testing/sysfs-bus-drivers-probe
F: Documentation/core-api/kobject.rst
F: Documentation/driver-api/driver-model/
F: drivers/base/
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 396097fdb3162..ecff32c3704b5 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -310,13 +310,18 @@ static ssize_t drivers_probe_store(const struct bus_type *bus,
const char *buf, size_t count)
{
struct device *dev;
- int err = -EINVAL;
+ int err;
dev = bus_find_device_by_name(bus, NULL, buf);
if (!dev)
return -ENODEV;
- if (bus_rescan_devices_helper(dev, NULL) == 0)
+ err = bus_rescan_devices_helper(dev, NULL);
+ if (!err)
err = count;
+ else if (err == -EPROBE_DEFER)
+ err = -EAGAIN;
+ else
+ err = -EINVAL;
put_device(dev);
return err;
}
--
2.56.0