mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
driver core: use READ_ONCE() for dev->driver in dev_has_sync_state()
dev_has_sync_state() reads dev->driver twice without holding
device_lock() -- once for the NULL check and once to dereference
->sync_state. Some callers only hold device_links_write_lock, which
doesn't prevent a concurrent unbind from clearing dev->driver via
device_unbind_cleanup().
Fix it by reading dev->driver exactly once with READ_ONCE(), pairing
with the WRITE_ONCE() in device_set_driver().
Link: https://lore.kernel.org/driver-core/DHW8QPU1VU1F.3P6PH69HLFBYC@kernel.org/
Fixes: ac338acf51 ("driver core: Add dev_has_sync_state()")
Reviewed-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Saravana Kannan <saravanak@kernel.org>
Link: https://patch.msgid.link/20260418162221.1121873-1-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
parent
c9447f1013
commit
e9506871a8
|
|
@ -1063,9 +1063,12 @@ static inline void device_lock_assert(struct device *dev)
|
|||
|
||||
static inline bool dev_has_sync_state(struct device *dev)
|
||||
{
|
||||
struct device_driver *drv;
|
||||
|
||||
if (!dev)
|
||||
return false;
|
||||
if (dev->driver && dev->driver->sync_state)
|
||||
drv = READ_ONCE(dev->driver);
|
||||
if (drv && drv->sync_state)
|
||||
return true;
|
||||
if (dev->bus && dev->bus->sync_state)
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user