ARM: 8524/1: driver cohandle -EPROBE_DEFER from bus_type.match()
authorTomeu Vizoso <tomeu.vizoso@collabora.com>
Mon, 15 Feb 2016 08:25:06 +0000 (09:25 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Tue, 16 Feb 2016 16:28:51 +0000 (16:28 +0000)
Allow implementations of the match() callback in struct bus_type to
return errors and if it's -EPROBE_DEFER then queue the device for
deferred probing.

This is useful to buses such as AMBA in which devices are registered
before their matching information can be retrieved from the HW
(typically because a clock driver hasn't probed yet).

[changed if-else code structure, adjusted documentation to match the code,
extended comments]

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Documentation/driver-model/porting.txt
drivers/base/dd.c
include/linux/device.h

index 92d86f7271b4d960431e3333ce5d0de3b9f9889e..453053f1661f47e2dc3c75d0564b2105e8ddfb22 100644 (file)
@@ -340,8 +340,10 @@ comparison:
 
   int (*match)(struct device * dev, struct device_driver * drv);
 
-match should return '1' if the driver supports the device, and '0'
-otherwise. 
+match should return positive value if the driver supports the device,
+and zero otherwise. It may also return error code (for example
+-EPROBE_DEFER) if determining that given driver supports the device is
+not possible.
 
 When a device is registered, the bus's list of drivers is iterated
 over. bus->match() is called for each one until a match is found. 
index c4da2df62e02525617a23ebe68fff4af0bb69350..16688f50729cfac7112a740804c00b226680ca4a 100644 (file)
@@ -560,6 +560,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
        struct device_attach_data *data = _data;
        struct device *dev = data->dev;
        bool async_allowed;
+       int ret;
 
        /*
         * Check if device has already been claimed. This may
@@ -570,8 +571,17 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
        if (dev->driver)
                return -EBUSY;
 
-       if (!driver_match_device(drv, dev))
+       ret = driver_match_device(drv, dev);
+       if (ret == 0) {
+               /* no match */
                return 0;
+       } else if (ret == -EPROBE_DEFER) {
+               dev_dbg(dev, "Device match requests probe deferral\n");
+               driver_deferred_probe_add(dev);
+       } else if (ret < 0) {
+               dev_dbg(dev, "Bus failed to match device: %d", ret);
+               return ret;
+       } /* ret > 0 means positive match */
 
        async_allowed = driver_allows_async_probing(drv);
 
@@ -691,6 +701,7 @@ void device_initial_probe(struct device *dev)
 static int __driver_attach(struct device *dev, void *data)
 {
        struct device_driver *drv = data;
+       int ret;
 
        /*
         * Lock device and try to bind to it. We drop the error
@@ -702,8 +713,17 @@ static int __driver_attach(struct device *dev, void *data)
         * is an error.
         */
 
-       if (!driver_match_device(drv, dev))
+       ret = driver_match_device(drv, dev);
+       if (ret == 0) {
+               /* no match */
                return 0;
+       } else if (ret == -EPROBE_DEFER) {
+               dev_dbg(dev, "Device match requests probe deferral\n");
+               driver_deferred_probe_add(dev);
+       } else if (ret < 0) {
+               dev_dbg(dev, "Bus failed to match device: %d", ret);
+               return ret;
+       } /* ret > 0 means positive match */
 
        if (dev->parent)        /* Needed for USB */
                device_lock(dev->parent);
index 6d6f1fec092fe5df78671f5b352931a2edae4aca..8f2ec813d21556d90cb373ec2e45941b0eeef1cc 100644 (file)
@@ -70,8 +70,11 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
  * @dev_groups:        Default attributes of the devices on the bus.
  * @drv_groups: Default attributes of the device drivers on the bus.
  * @match:     Called, perhaps multiple times, whenever a new device or driver
- *             is added for this bus. It should return a nonzero value if the
- *             given device can be handled by the given driver.
+ *             is added for this bus. It should return a positive value if the
+ *             given device can be handled by the given driver and zero
+ *             otherwise. It may also return error code if determining that
+ *             the driver supports the device is not possible. In case of
+ *             -EPROBE_DEFER it will queue the device for deferred probing.
  * @uevent:    Called when a device is added, removed, or a few other things
  *             that generate uevents to add the environment variables.
  * @probe:     Called when a new device or driver add to this bus, and callback