mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
Driver core: fix race in dev_driver_string
This patch (as1310) works around a race in dev_driver_string(). If the device is unbound while the function is running, dev->driver might become NULL after we test it and before we dereference it. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Cc: stable <stable@kernel.org> Cc: Oliver Neukum <oliver@neukum.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
c60e0504c8
commit
3589972e51
1 changed files with 8 additions and 1 deletions
|
@ -56,7 +56,14 @@ static inline int device_is_not_partition(struct device *dev)
|
|||
*/
|
||||
const char *dev_driver_string(const struct device *dev)
|
||||
{
|
||||
return dev->driver ? dev->driver->name :
|
||||
struct device_driver *drv;
|
||||
|
||||
/* dev->driver can change to NULL underneath us because of unbinding,
|
||||
* so be careful about accessing it. dev->bus and dev->class should
|
||||
* never change once they are set, so they don't need special care.
|
||||
*/
|
||||
drv = ACCESS_ONCE(dev->driver);
|
||||
return drv ? drv->name :
|
||||
(dev->bus ? dev->bus->name :
|
||||
(dev->class ? dev->class->name : ""));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue