]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
driver core: Add deferred_probe attribute to devices in sysfs
authorBen Hutchings <ben.hutchings@codethink.co.uk>
Tue, 16 Aug 2016 13:34:18 +0000 (14:34 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Nov 2016 16:22:23 +0000 (17:22 +0100)
It is sometimes useful to know that a device is on the deferred probe
list rather than, say, not having a driver available.  Expose this
information to user-space.

Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/ABI/testing/sysfs-devices-deferred_probe [new file with mode: 0644]
drivers/base/base.h
drivers/base/core.c
drivers/base/dd.c

diff --git a/Documentation/ABI/testing/sysfs-devices-deferred_probe b/Documentation/ABI/testing/sysfs-devices-deferred_probe
new file mode 100644 (file)
index 0000000..58553d7
--- /dev/null
@@ -0,0 +1,12 @@
+What:          /sys/devices/.../deferred_probe
+Date:          August 2016
+Contact:       Ben Hutchings <ben.hutchings@codethink.co.uk>
+Description:
+               The /sys/devices/.../deferred_probe attribute is
+               present for all devices.  If a driver detects during
+               probing a device that a related device is not yet
+               ready, it may defer probing of the first device.  The
+               kernel will retry probing the first device after any
+               other device is successfully probed.  This attribute
+               reads as 1 if probing of this device is currently
+               deferred, or 0 otherwise.
index e19b1008e5fb08b1099e5f5d8f0dc86dfc24bde5..ada9dce34e6d8a8373d3d08d5c28b3f6b55ac427 100644 (file)
@@ -141,6 +141,8 @@ extern void device_unblock_probing(void);
 extern struct kset *devices_kset;
 extern void devices_kset_move_last(struct device *dev);
 
+extern struct device_attribute dev_attr_deferred_probe;
+
 #if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
 extern void module_add_driver(struct module *mod, struct device_driver *drv);
 extern void module_remove_driver(struct device_driver *drv);
index d0c9df5cdd9ed5f2098500dabb8a6b7b16cfb244..b8b2f61054763f3128b448f6e7e25110b109c3c6 100644 (file)
@@ -1060,8 +1060,14 @@ static int device_add_attrs(struct device *dev)
                        goto err_remove_dev_groups;
        }
 
+       error = device_create_file(dev, &dev_attr_deferred_probe);
+       if (error)
+               goto err_remove_online;
+
        return 0;
 
+ err_remove_online:
+       device_remove_file(dev, &dev_attr_online);
  err_remove_dev_groups:
        device_remove_groups(dev, dev->groups);
  err_remove_type_groups:
@@ -1079,6 +1085,7 @@ static void device_remove_attrs(struct device *dev)
        struct class *class = dev->class;
        const struct device_type *type = dev->type;
 
+       device_remove_file(dev, &dev_attr_deferred_probe);
        device_remove_file(dev, &dev_attr_online);
        device_remove_groups(dev, dev->groups);
 
index 43be1cc751a4af09b4bfbf4377bd417171aa1d89..a48cf444eca55ba5636b7298af55f9cf62c77651 100644 (file)
@@ -53,6 +53,19 @@ static LIST_HEAD(deferred_probe_pending_list);
 static LIST_HEAD(deferred_probe_active_list);
 static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
 
+static ssize_t deferred_probe_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       bool value;
+
+       mutex_lock(&deferred_probe_mutex);
+       value = !list_empty(&dev->p->deferred_probe);
+       mutex_unlock(&deferred_probe_mutex);
+
+       return sprintf(buf, "%d\n", value);
+}
+DEVICE_ATTR_RO(deferred_probe);
+
 /*
  * In some cases, like suspend to RAM or hibernation, It might be reasonable
  * to prohibit probing of devices as it could be unsafe.