diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2009-12-04 11:06:57 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-12-18 14:04:17 -0800 |
commit | fa8e26457e28606446f9afd6566cead9d0418b73 (patch) | |
tree | c42582b761ee36568b11f1415c1d30331c1ae496 /drivers | |
parent | 9f2813ec1f4868d07d8a16f4a9c4932819fc5d8e (diff) |
Driver core: fix race in dev_driver_string
commit 3589972e51fac1e02d0aaa576fa47f568cb94d40 upstream.
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: Oliver Neukum <oliver@neukum.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/core.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index 6bee6af8d8e1..109317948d5d 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -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 : "")); } |