Skip to content

Commit a6d38e9

Browse files
committed
PM: sleep: stats: Use locking in dpm_save_failed_dev()
Because dpm_save_failed_dev() may be called simultaneously by multiple failing device PM functions, the state of the suspend_stats fields updated by it may become inconsistent. Prevent that from happening by using a lock in dpm_save_failed_dev(). Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Stanislaw Gruszka <[email protected]> Reviewed-by: Ulf Hansson <[email protected]>
1 parent 4add3e7 commit a6d38e9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/power/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,18 @@ struct suspend_stats {
325325
};
326326

327327
static struct suspend_stats suspend_stats;
328+
static DEFINE_MUTEX(suspend_stats_lock);
328329

329330
void dpm_save_failed_dev(const char *name)
330331
{
332+
mutex_lock(&suspend_stats_lock);
333+
331334
strscpy(suspend_stats.failed_devs[suspend_stats.last_failed_dev],
332335
name, sizeof(suspend_stats.failed_devs[0]));
333336
suspend_stats.last_failed_dev++;
334337
suspend_stats.last_failed_dev %= REC_FAILED_NUM;
338+
339+
mutex_unlock(&suspend_stats_lock);
335340
}
336341

337342
void dpm_save_failed_step(enum suspend_stat_step step)

0 commit comments

Comments
 (0)