Driver bind/unbind and __devinit
Hi,
Many drivers have their probe routines declared as __devinit which is a no-op unless CONFIG_HOTPLUG is set. However driver's bind/unbind attributes are created unconditionally, as fas as I can see. Would not it cause an oops if someone tries to use these attributes with CONFIG_HOTPLUG=N? Am I missing something?
Also, unbind implementation does not seem safe - we check the driver before taking device's semaphore so we risk unbinding wrong driver (in the unlikely event that we manage to unbind and bind another driver in another thread).
--
Dmitry
Quoted 7 lines · Dmitry Torokhov
Hi,
Many drivers have their probe routines declared as
__devinitwhich is a no-op unlessCONFIG_HOTPLUGis set. However driver's bind/unbind attributes are created unconditionally, as fas as I can see. Would not it cause an oops if someone tries to use these attributes withCONFIG_HOTPLUG=N? Am I missing something?
You are missing the CONFIG_HOTPLUG checks around the functions that add and check the device ids from these sysfs files. If CONFIG_HOTPLUG is not enabled, those files do not do anything.
In 2.6.16, CONFIG_HOTPLUG is moving under CONFIG_EMBEDDED, so the odds of people disabling it are going to be pretty small now.
Quoted 4 lines
Also, unbind implementation does not seem safe - we check the driver before taking device's semaphore so we risk unbinding wrong driver (in the unlikely event that we manage to unbind and bind another driver in another thread).
Do you have a suggestion as to how to fix this?
thanks,
greg k-h
Quoted 9 lines · Greg KH
Quoted 7 lines · Dmitry Torokhov
Hi,
Many drivers have their probe routines declared as
__devinitwhich is a no-op unlessCONFIG_HOTPLUGis set. However driver's bind/unbind attributes are created unconditionally, as fas as I can see. Would not it cause an oops if someone tries to use these attributes withCONFIG_HOTPLUG=N? Am I missing something?
Quoted 4 lines
You are missing the
CONFIG_HOTPLUGchecks around the functions that add and check the device ids from these sysfs files. IfCONFIG_HOTPLUGis not enabled, those files do not do anything.
I am slow today... I don't see any dependencies on CONFIG_HOTPLUG in drivers/base... Or you talking about one particular subsystem that handles this correctly?
Quoted 3 lines
In 2.6.16,
CONFIG_HOTPLUGis moving underCONFIG_EMBEDDED, so the odds of people disabling it are going to be pretty small now.
I dont think this is a valid argument.
Quoted 7 lines
Quoted 4 lines
Also, unbind implementation does not seem safe - we check the driver before taking device's semaphore so we risk unbinding wrong driver (in the unlikely event that we manage to unbind and bind another driver in another thread).
Do you have a suggestion as to how to fix this?
I think we could take the semaphore before checking driver and then use __device_release_driver(). But we'd need to make it global or move bind/unbind code into drivers/base/dd.c
--
Dmitry
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines · Greg KH
Quoted 7 lines · Dmitry Torokhov
Hi,
Many drivers have their probe routines declared as
__devinitwhich is a no-op unlessCONFIG_HOTPLUGis set. However driver's bind/unbind attributes are created unconditionally, as fas as I can see. Would not it cause an oops if someone tries to use these attributes withCONFIG_HOTPLUG=N? Am I missing something?
Quoted 8 lines
Quoted 4 lines
You are missing the
CONFIG_HOTPLUGchecks around the functions that add and check the device ids from these sysfs files. IfCONFIG_HOTPLUGis not enabled, those files do not do anything.I am slow today... I don't see any dependencies on
CONFIG_HOTPLUGindrivers/base... Or you talking about one particular subsystem that handles this correctly?
Ugh, very sorry about that, I was thinking of the USB and PCI new_id stuff. You are right.
Yes, bind happening after the __init data section is thrown away, if CONFIG_HOTPLUG is not enabled would be a bad thing. But unbind can stay. I'll go make up a patch for that.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Also, unbind implementation does not seem safe - we check the driver before taking device's semaphore so we risk unbinding wrong driver (in the unlikely event that we manage to unbind and bind another driver in another thread).
Do you have a suggestion as to how to fix this?
I think we could take the semaphore before checking driver and then use
__device_release_driver(). But we'd need to make it global or move bind/unbind code intodrivers/base/dd.c
I don't have a problem moving the code if it makes it easier. Have a patch? :)
thanks,
greg k-h
Quoted 20 lines · Greg KH
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines · Greg KH
Quoted 7 lines · Dmitry Torokhov
Hi,
Many drivers have their probe routines declared as
__devinitwhich is a no-op unlessCONFIG_HOTPLUGis set. However driver's bind/unbind attributes are created unconditionally, as fas as I can see. Would not it cause an oops if someone tries to use these attributes withCONFIG_HOTPLUG=N? Am I missing something?Quoted 8 lines
Quoted 4 lines
You are missing the
CONFIG_HOTPLUGchecks around the functions that add and check the device ids from these sysfs files. IfCONFIG_HOTPLUGis not enabled, those files do not do anything.I am slow today... I don't see any dependencies on
CONFIG_HOTPLUGindrivers/base... Or you talking about one particular subsystem that handles this correctly?
Quoted 7 lines
Ugh, very sorry about that, I was thinking of the USB and PCI
new_idstuff. You are right.Yes, bind happening after the
__initdata section is thrown away, ifCONFIG_HOTPLUGis not enabled would be a bad thing. But unbind can stay. I'll go make up a patch for that.
Unbind may invoke ->remove code which is __devexit[_p] and may be also discarded if !MODULE && !HOTPLUG.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Also, unbind implementation does not seem safe - we check the driver before taking device's semaphore so we risk unbinding wrong driver (in the unlikely event that we manage to unbind and bind another driver in another thread).
Do you have a suggestion as to how to fix this?
Quoted 7 lines
Quoted 3 lines
I think we could take the semaphore before checking driver and then use
__device_release_driver(). But we'd need to make it global or move bind/unbind code intodrivers/base/dd.cI don't have a problem moving the code if it makes it easier. Have a patch? :)
Just handwaving for now ;)
--
Dmitry