Skip to content

Commit eed6e41

Browse files
Saravana Kannangregkh
authored andcommitted
driver core: Fix locking bug in deferred_probe_timeout_work_func()
list_for_each_entry_safe() is only useful if we are deleting nodes in a linked list within the loop. It doesn't protect against other threads adding/deleting nodes to the list in parallel. We need to grab deferred_probe_mutex when traversing the deferred_probe_pending_list. Cc: [email protected] Fixes: 25b4e70 ("driver core: allow stopping deferred probe after init") Signed-off-by: Saravana Kannan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e49d033 commit eed6e41

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/base/dd.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,16 @@ int driver_deferred_probe_check_state(struct device *dev)
292292

293293
static void deferred_probe_timeout_work_func(struct work_struct *work)
294294
{
295-
struct device_private *private, *p;
295+
struct device_private *p;
296296

297297
driver_deferred_probe_timeout = 0;
298298
driver_deferred_probe_trigger();
299299
flush_work(&deferred_probe_work);
300300

301-
list_for_each_entry_safe(private, p, &deferred_probe_pending_list, deferred_probe)
302-
dev_info(private->device, "deferred probe pending\n");
301+
mutex_lock(&deferred_probe_mutex);
302+
list_for_each_entry(p, &deferred_probe_pending_list, deferred_probe)
303+
dev_info(p->device, "deferred probe pending\n");
304+
mutex_unlock(&deferred_probe_mutex);
303305
wake_up_all(&probe_timeout_waitqueue);
304306
}
305307
static DECLARE_DELAYED_WORK(deferred_probe_timeout_work, deferred_probe_timeout_work_func);

0 commit comments

Comments
 (0)