[PATCH] driver core: add devices to deferred probe list when unbinding consumers

From: Lucas Stach
Date: Wed Mar 08 2017 - 06:51:03 EST


When a device is unbound due to the provider of one of the resources going
away, add it to the deferred probe list. This way the consumer device
driver gets a chance to rebind itself if the provider is rebound later on.

Signed-off-by: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
---
drivers/base/base.h | 1 +
drivers/base/core.c | 2 ++
drivers/base/dd.c | 2 +-
3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index e19b1008e5fb..c37d42450886 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -113,6 +113,7 @@ extern void device_release_driver_internal(struct device *dev,

extern void driver_detach(struct device_driver *drv);
extern int driver_probe_device(struct device_driver *drv, struct device *dev);
+extern void driver_deferred_probe_add(struct device *dev);
extern void driver_deferred_probe_del(struct device *dev);
static inline int driver_match_device(struct device_driver *drv,
struct device *dev)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 8c25e68e67d7..860e1cf195b9 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -572,6 +572,8 @@ void device_links_unbind_consumers(struct device *dev)

device_release_driver_internal(consumer, NULL,
consumer->parent);
+ driver_deferred_probe_add(consumer);
+
put_device(consumer);
goto start;
}
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index a1fbf55c4d3a..a0217d76a0f2 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -115,7 +115,7 @@ static void deferred_probe_work_func(struct work_struct *work)
}
static DECLARE_WORK(deferred_probe_work, deferred_probe_work_func);

-static void driver_deferred_probe_add(struct device *dev)
+void driver_deferred_probe_add(struct device *dev)
{
mutex_lock(&deferred_probe_mutex);
if (list_empty(&dev->p->deferred_probe)) {
--
2.11.0