Skip to content

Commit a4b64b8

Browse files
committed
PM: sleep: Move some assignments from under a lock
The async_error and pm_transition variables are set under dpm_list_mtx in multiple places in the system-wide device PM core code, which is unnecessary and confusing, so rearrange the code so that the variables in question are set before acquiring the lock. While at it, add some empty code lines around locking to improve the consistency of the code. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Stanislaw Gruszka <[email protected]> Reviewed-by: Ulf Hansson <[email protected]>
1 parent ac6f87a commit a4b64b8

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

drivers/base/power/main.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,9 @@ static void dpm_noirq_resume_devices(pm_message_t state)
707707
trace_suspend_resume(TPS("dpm_resume_noirq"), state.event, true);
708708

709709
async_error = 0;
710+
pm_transition = state;
710711

711712
mutex_lock(&dpm_list_mtx);
712-
pm_transition = state;
713713

714714
/*
715715
* Trigger the resume of "async" devices upfront so they don't have to
@@ -847,9 +847,9 @@ void dpm_resume_early(pm_message_t state)
847847
trace_suspend_resume(TPS("dpm_resume_early"), state.event, true);
848848

849849
async_error = 0;
850+
pm_transition = state;
850851

851852
mutex_lock(&dpm_list_mtx);
852-
pm_transition = state;
853853

854854
/*
855855
* Trigger the resume of "async" devices upfront so they don't have to
@@ -1012,10 +1012,11 @@ void dpm_resume(pm_message_t state)
10121012
trace_suspend_resume(TPS("dpm_resume"), state.event, true);
10131013
might_sleep();
10141014

1015-
mutex_lock(&dpm_list_mtx);
10161015
pm_transition = state;
10171016
async_error = 0;
10181017

1018+
mutex_lock(&dpm_list_mtx);
1019+
10191020
/*
10201021
* Trigger the resume of "async" devices upfront so they don't have to
10211022
* wait for the "non-async" ones they don't depend on.
@@ -1294,10 +1295,12 @@ static int dpm_noirq_suspend_devices(pm_message_t state)
12941295
int error = 0;
12951296

12961297
trace_suspend_resume(TPS("dpm_suspend_noirq"), state.event, true);
1297-
mutex_lock(&dpm_list_mtx);
1298+
12981299
pm_transition = state;
12991300
async_error = 0;
13001301

1302+
mutex_lock(&dpm_list_mtx);
1303+
13011304
while (!list_empty(&dpm_late_early_list)) {
13021305
struct device *dev = to_device(dpm_late_early_list.prev);
13031306

@@ -1320,7 +1323,9 @@ static int dpm_noirq_suspend_devices(pm_message_t state)
13201323
if (error || async_error)
13211324
break;
13221325
}
1326+
13231327
mutex_unlock(&dpm_list_mtx);
1328+
13241329
async_synchronize_full();
13251330
if (!error)
13261331
error = async_error;
@@ -1470,11 +1475,14 @@ int dpm_suspend_late(pm_message_t state)
14701475
int error = 0;
14711476

14721477
trace_suspend_resume(TPS("dpm_suspend_late"), state.event, true);
1473-
wake_up_all_idle_cpus();
1474-
mutex_lock(&dpm_list_mtx);
1478+
14751479
pm_transition = state;
14761480
async_error = 0;
14771481

1482+
wake_up_all_idle_cpus();
1483+
1484+
mutex_lock(&dpm_list_mtx);
1485+
14781486
while (!list_empty(&dpm_suspended_list)) {
14791487
struct device *dev = to_device(dpm_suspended_list.prev);
14801488

@@ -1498,7 +1506,9 @@ int dpm_suspend_late(pm_message_t state)
14981506
if (error || async_error)
14991507
break;
15001508
}
1509+
15011510
mutex_unlock(&dpm_list_mtx);
1511+
15021512
async_synchronize_full();
15031513
if (!error)
15041514
error = async_error;
@@ -1745,9 +1755,11 @@ int dpm_suspend(pm_message_t state)
17451755
devfreq_suspend();
17461756
cpufreq_suspend();
17471757

1748-
mutex_lock(&dpm_list_mtx);
17491758
pm_transition = state;
17501759
async_error = 0;
1760+
1761+
mutex_lock(&dpm_list_mtx);
1762+
17511763
while (!list_empty(&dpm_prepared_list)) {
17521764
struct device *dev = to_device(dpm_prepared_list.prev);
17531765

@@ -1771,7 +1783,9 @@ int dpm_suspend(pm_message_t state)
17711783
if (error || async_error)
17721784
break;
17731785
}
1786+
17741787
mutex_unlock(&dpm_list_mtx);
1788+
17751789
async_synchronize_full();
17761790
if (!error)
17771791
error = async_error;

0 commit comments

Comments
 (0)