Re: [PATCH] driver core: Make sure device detached from driver before deleting it

From: Rafael J. Wysocki
Date: Wed Oct 18 2017 - 06:14:01 EST


On Wednesday, October 18, 2017 7:49:26 AM CEST Jeffy Chen wrote:
> There are cases we call device_del() without detaching it from the
> driver(e.g. spi core del children devices).

But device_del() itself detaches the device from its driver.

> Signed-off-by: Jeffy Chen <jeffy.chen@xxxxxxxxxxxxxx>
> ---
>
> drivers/base/core.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 12ebd055724c..717efc3020af 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -1951,6 +1951,8 @@ void device_del(struct device *dev)
> struct kobject *glue_dir = NULL;
> struct class_interface *class_intf;
>
> + device_release_driver(dev);
> +
> /* Notify clients of device removal. This call must come
> * before dpm_sysfs_remove().
> */
>

But device_del() calls bus_remove_device() which in turn calls
device_release_driver(), so this looks like an ordering issue to me.

What *exactly* is not working? Or rather, what symptoms do you see?

Thanks,
Rafael