diff mbox series

[v2,-next,1/2] PM: suspend: expand the assignment scope of the pm_suspend_target_state

Message ID 20220630005718.309178-2-xiongxin@kylinos.cn
State New
Headers show
Series [v2,-next,1/2] PM: suspend: expand the assignment scope of the pm_suspend_target_state | expand

Commit Message

xiongxin June 30, 2022, 12:57 a.m. UTC
The pm_suspend_target_state variable can be used as a suspend state
identifier and given to the specific device driver as a code judgment;

Because the suspend_prepare() function is time-consuming for the
operation of freezing processes, and this stage is actually in the suspend
stage, it is necessary to expand the scope of the pm_suspend_target_state
variable to be assigned to the suspend state at enter_state() function;

Another reason is that the specific device driver can locate whether it is
in the suspend state based on this variable, so as to determine the
validity of its wake-up source.

Signed-off-by: xiongxin <xiongxin@kylinos.cn>
 kernel/power/suspend.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series


diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 827075944d28..4cfa464600bf 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -48,7 +48,7 @@  const char *mem_sleep_states[PM_SUSPEND_MAX];
 suspend_state_t mem_sleep_current = PM_SUSPEND_TO_IDLE;
 suspend_state_t mem_sleep_default = PM_SUSPEND_MAX;
-suspend_state_t pm_suspend_target_state;
+suspend_state_t pm_suspend_target_state = PM_SUSPEND_ON;
 unsigned int pm_suspend_global_flags;
@@ -564,6 +564,12 @@  static int enter_state(suspend_state_t state)
 	if (state == PM_SUSPEND_TO_IDLE)
+	/*
+	 * Expand the scope of suspend state for suspend operations
+	 * performed from the /sys/power/state entry.
+	 */
+	pm_suspend_target_state = state;
 	if (sync_on_suspend_enabled) {
 		trace_suspend_resume(TPS("sync_filesystems"), 0, true);
@@ -590,6 +596,7 @@  static int enter_state(suspend_state_t state)
 	pm_pr_dbg("Finishing wakeup.\n");
+	pm_suspend_target_state = PM_SUSPEND_ON;
 	return error;