Skip to content

Commit 86686b8

Browse files
committed
PM: sleep: Simplify dpm_suspended_list walk in dpm_resume()
Notice that devices can be moved to dpm_prepared_list before running their resume callbacks, in analogy with dpm_noirq_resume_devices() and dpm_resume_early(), because doing so will not affect the final ordering of that list. Namely, if a device is the first dpm_suspended_list entry while dpm_list_mtx is held, it has not been removed so far and it cannot be removed until dpm_list_mtx is released, so moving it to dpm_prepared_list at that point is valid. If it is removed later, while its resume callback is running, it will be deleted from dpm_prepared_list without changing the ordering of the other devices in that list. Accordingly, rearrange the while () loop in dpm_resume() to move devices to dpm_prepared_list before running their resume callbacks and implify the locking and device reference counting in it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
1 parent b017500 commit 86686b8

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

drivers/base/power/main.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,25 +1017,19 @@ void dpm_resume(pm_message_t state)
10171017

10181018
while (!list_empty(&dpm_suspended_list)) {
10191019
dev = to_device(dpm_suspended_list.next);
1020-
1021-
get_device(dev);
1020+
list_move_tail(&dev->power.entry, &dpm_prepared_list);
10221021

10231022
if (!dev->power.async_in_progress) {
1023+
get_device(dev);
1024+
10241025
mutex_unlock(&dpm_list_mtx);
10251026

10261027
device_resume(dev, state, false);
10271028

1029+
put_device(dev);
1030+
10281031
mutex_lock(&dpm_list_mtx);
10291032
}
1030-
1031-
if (!list_empty(&dev->power.entry))
1032-
list_move_tail(&dev->power.entry, &dpm_prepared_list);
1033-
1034-
mutex_unlock(&dpm_list_mtx);
1035-
1036-
put_device(dev);
1037-
1038-
mutex_lock(&dpm_list_mtx);
10391033
}
10401034
mutex_unlock(&dpm_list_mtx);
10411035
async_synchronize_full();

0 commit comments

Comments
 (0)