driver core: Make sure device detached from driver before deleting it
PATCH 1/1 driver core: Make sure device detached from driver before deleting it
There are cases we call device_del() without detaching it from the driver(e.g. spi core del children devices).
---
drivers/base/core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/base/core.c +2 -0
@@ -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(). */
Signature · 1 line
2.11.0
Greg Kroah-Hartman
maintainerQuoted 2 lines · Jeffy Chen
There are cases we call
device_del()without detaching it from the driver(e.g. spi core del children devices).
Why would you do that? Shouldn't that be fixed instead of this odd work-around for a broken bus?
thanks,
greg k-h
Hi Greg,
Thanks for your reply.
Quoted 6 lines · Greg Kroah-Hartman
Quoted 2 lines · Jeffy Chen
Quoted 2 lines
There are cases we call
device_del()without detaching it from the driver(e.g. spi core del children devices).Why would you do that? Shouldn't that be fixed instead of this odd work-around for a broken bus?
i was thinking since the device_unregister() is called everywhere, maybe there are some other drivers missing that too?
and the driver calls device_add(), then the core attaches the device to the driver automatically, maybe it would make sense to let the core automatic detach it somehow...
but i know nothing about driver core, maybe i should fix it in spi core, i'll send new patch for that :)
Quoted 6 lines
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 14 lines · jeffy
Hi Greg,
Thanks for your reply.
Quoted 6 lines · Greg Kroah-Hartman
Quoted 2 lines · Jeffy Chen
Quoted 2 lines
There are cases we call
device_del()without detaching it from the driver(e.g. spi core del children devices).Why would you do that? Shouldn't that be fixed instead of this odd work-around for a broken bus?
i was thinking since the
device_unregister()is called everywhere, maybe there are some other drivers missing that too?
Quoted 6 lines
and the driver calls
device_add(), then the core attaches the device to the driver automatically, maybe it would make sense to let the core automatic detach it somehow...but i know nothing about driver core, maybe i should fix it in spi core, i'll send new patch for that :)
The SPI core should have some internal housekeeping to do there as well, right? Is this the only bus that gets this "wrong"?
thanks,
greg k-h
Hi Greg,
Quoted 3 lines · Greg Kroah-Hartman
The SPI core should have some internal housekeeping to do there as well, right? Is this the only bus that gets this "wrong"?
hmm, i checked i2c code, it has the same issue:
void i2c_unregister_device(struct i2c_client *client)
{
if (client->dev.of_node)
of_node_clear_flag(client->dev.of_node, OF_POPULATED);
if (ACPI_COMPANION(&client->dev))
acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
device_unregister(&client->dev);
}not sure about others, maybe mfd-core too...
Quoted 6 lines
thanks,
greg k-h
Quoted 6 lines · Greg Kroah-Hartman
Quoted 2 lines · Jeffy Chen
There are cases we call
device_del()without detaching it from the driver(e.g. spi core del children devices).Why would you do that? Shouldn't that be fixed instead of this odd work-around for a broken bus?
Not that I ever looked at that bit of the SPI stack before but this feels like an interface bug in the driver core, it's really surprising that unregistering a device doesn't clean it up. That's what other unregister interfaces do. If this is buggy it looks like the platform bus will also be buggy, it's just doing a del and a put (plus some stuff to free resources) which is all device_unregster() does.
Quoted 13 lines · CEST Mark Brown
--3mkxuqf5z23bfztf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inlineQuoted 6 lines · Greg Kroah-Hartman
Quoted 2 lines · Jeffy Chen
There are cases we call
device_del()without detaching it from the driver(e.g. spi core del children devices).Why would you do that? Shouldn't that be fixed instead of this odd work-around for a broken bus?
Quoted 6 lines
Not that I ever looked at that bit of the SPI stack before but this feels like an interface bug in the driver core, it's really surprising that unregistering a device doesn't clean it up. That's what other unregister interfaces do. If this is buggy it looks like the platform bus will also be buggy, it's just doing a del and a put (plus some stuff to free resources) which is all
device_unregster()does.
device_del() calls bus_remove_device() which then calls device_release_driver() eventually.
So there is something going wrong, but that's not a missing device_release_driver() call. :-)
Quoted 2 lines · CEST Jeffy Chen
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.
Quoted 12 lines
Signed-off-by Jeffy Chen <[email protected]>---
drivers/base/core.c | 2 ++ 1 file changed, 2 insertions(+)drivers/base/core.c +0
-0
drivers/base/core.c void device_del(struct device *dev) · line 1958
Quoted 8 lines
drivers/base/core.c +2
-0@@ -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
Hi Rafael,
Thanks for your reply.
Quoted 3 lines · Rafael J. Wysocki
But
device_del()callsbus_remove_device()which in turn callsdevice_release_driver(), so this looks like an ordering issue to me.
uh, right, didn't notice that, it indeed to be a ordering issue...
it turns out in device_del() we are calling device_links_purge() before bus_remove_device()...
Quoted 2 lines
What*exactly* is not working? Or rather, what symptoms do you see?
my board has these devices:
spi master device->spi child device->spi based pwm->pwm_bl
and i add a device link to the pwm and pwm_bl, and got a warning about the pwm not unbound:
static void device_links_purge(struct device *dev) {
...
list_for_each_entry_safe_reverse(link, ln,
&dev->links.consumers, s_node) {
WARN_ON(link->status != DL_STATE_DORMANT &&
link->status != DL_STATE_NONE); <-- warning here!
__device_link_del(link);
}and i was confused by:
static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data,
const char *hwname, struct genl_info *info)
{
...
device_release_driver(data->dev);
device_unregister(data->dev);and adding that device_release_driver hide that issue(oops...)
so we should move device_links_purge() after bus_remove_device() in device_del() right? maybe after device_remove_properties(), and that did solve the issue :)
Quoted 2 lines
Thanks,
Rafael
Hi Rafael,
Quoted 6 lines · jeffy
Quoted 1 line
my board has these devices:
spi masterdevice->spichilddevice->spibasedpwm->pwm_bland i add a device link to the pwm and
pwm_bl, and got a warning about the pwm not unbound:
sorry, it happens when i try to unbind the spi child device, and it's warning about the consumer(pwm_bl) not unbound.
Quoted 10 lines
static void
device_links_purge(struct device *dev){
...
list_for_each_entry_safe_reverse(link, ln,&dev->links.consumers, s_node) { WARN_ON(link->status != DL_STATE_DORMANT && link->status != DL_STATE_NONE); <-- warning here! __device_link_del(link); }
and i've send a new patch to reorder the device_links_purge() and bus_remove_device, thanks again :)
Quoted 22 lines · CEST jeffy
Hi Rafael,
Quoted 6 lines · jeffy
Quoted 1 line
my board has these devices:
spi masterdevice->spichilddevice->spibasedpwm->pwm_bland i add a device link to the pwm and
pwm_bl, and got a warning about the pwm not unbound:sorry, it happens when i try to unbind the spi child device, and it's warning about the
consumer(pwm_bl)not unbound.Quoted 10 lines
static void
device_links_purge(struct device *dev){
...
list_for_each_entry_safe_reverse(link, ln,&dev->links.consumers, s_node) { WARN_ON(link->status != DL_STATE_DORMANT && link->status != DL_STATE_NONE); <-- warning here! __device_link_del(link); }
Quoted 2 lines
and i've send a new patch to reorder the
device_links_purge()andbus_remove_device, thanks again :)
Which I'm not sure is the right approach just yet.
I'll follow up in the patch thread in any case.
Thanks,
Rafael
Quoted 22 lines · CEST jeffy
Hi Rafael,
Quoted 6 lines · jeffy
Quoted 1 line
my board has these devices:
spi masterdevice->spichilddevice->spibasedpwm->pwm_bland i add a device link to the pwm and
pwm_bl, and got a warning about the pwm not unbound:sorry, it happens when i try to unbind the spi child device, and it's warning about the
consumer(pwm_bl)not unbound.Quoted 10 lines
static void
device_links_purge(struct device *dev){
...
list_for_each_entry_safe_reverse(link, ln,&dev->links.consumers, s_node) { WARN_ON(link->status != DL_STATE_DORMANT && link->status != DL_STATE_NONE); <-- warning here! __device_link_del(link); }
Quoted 2 lines
and i've send a new patch to reorder the
device_links_purge()andbus_remove_device, thanks again :)
Which I'm not sure is the right approach just yet.
I'll follow up in the patch thread in any case.
Thanks,
Rafael