Skip to content

Commit 656b803

Browse files
tomeuvRussell King
authored andcommitted
ARM: 8524/1: driver cohandle -EPROBE_DEFER from bus_type.match()
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>
1 parent 17f29d3 commit 656b803

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

Documentation/driver-model/porting.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,10 @@ comparison:
340340

341341
int (*match)(struct device * dev, struct device_driver * drv);
342342

343-
match should return '1' if the driver supports the device, and '0'
344-
otherwise.
343+
match should return positive value if the driver supports the device,
344+
and zero otherwise. It may also return error code (for example
345+
-EPROBE_DEFER) if determining that given driver supports the device is
346+
not possible.
345347

346348
When a device is registered, the bus's list of drivers is iterated
347349
over. bus->match() is called for each one until a match is found.

drivers/base/dd.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
560560
struct device_attach_data *data = _data;
561561
struct device *dev = data->dev;
562562
bool async_allowed;
563+
int ret;
563564

564565
/*
565566
* Check if device has already been claimed. This may
@@ -570,8 +571,17 @@ static int __device_attach_driver(struct device_driver *drv, void *_data)
570571
if (dev->driver)
571572
return -EBUSY;
572573

573-
if (!driver_match_device(drv, dev))
574+
ret = driver_match_device(drv, dev);
575+
if (ret == 0) {
576+
/* no match */
574577
return 0;
578+
} else if (ret == -EPROBE_DEFER) {
579+
dev_dbg(dev, "Device match requests probe deferral\n");
580+
driver_deferred_probe_add(dev);
581+
} else if (ret < 0) {
582+
dev_dbg(dev, "Bus failed to match device: %d", ret);
583+
return ret;
584+
} /* ret > 0 means positive match */
575585

576586
async_allowed = driver_allows_async_probing(drv);
577587

@@ -691,6 +701,7 @@ void device_initial_probe(struct device *dev)
691701
static int __driver_attach(struct device *dev, void *data)
692702
{
693703
struct device_driver *drv = data;
704+
int ret;
694705

695706
/*
696707
* 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)
702713
* is an error.
703714
*/
704715

705-
if (!driver_match_device(drv, dev))
716+
ret = driver_match_device(drv, dev);
717+
if (ret == 0) {
718+
/* no match */
706719
return 0;
720+
} else if (ret == -EPROBE_DEFER) {
721+
dev_dbg(dev, "Device match requests probe deferral\n");
722+
driver_deferred_probe_add(dev);
723+
} else if (ret < 0) {
724+
dev_dbg(dev, "Bus failed to match device: %d", ret);
725+
return ret;
726+
} /* ret > 0 means positive match */
707727

708728
if (dev->parent) /* Needed for USB */
709729
device_lock(dev->parent);

include/linux/device.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
7070
* @dev_groups: Default attributes of the devices on the bus.
7171
* @drv_groups: Default attributes of the device drivers on the bus.
7272
* @match: Called, perhaps multiple times, whenever a new device or driver
73-
* is added for this bus. It should return a nonzero value if the
74-
* given device can be handled by the given driver.
73+
* is added for this bus. It should return a positive value if the
74+
* given device can be handled by the given driver and zero
75+
* otherwise. It may also return error code if determining that
76+
* the driver supports the device is not possible. In case of
77+
* -EPROBE_DEFER it will queue the device for deferred probing.
7578
* @uevent: Called when a device is added, removed, or a few other things
7679
* that generate uevents to add the environment variables.
7780
* @probe: Called when a new device or driver add to this bus, and callback

0 commit comments

Comments
 (0)