Skip to content

Commit 4266e8f

Browse files
tuhaowenrafaeljw
authored andcommitted
PM: sleep: console: Fix the black screen issue
When the computer enters sleep status without a monitor connected, the system switches the console to the virtual terminal tty63(SUSPEND_CONSOLE). If a monitor is subsequently connected before waking up, the system skips the required VT restoration process during wake-up, leaving the console on tty63 instead of switching back to tty1. To fix this issue, a global flag vt_switch_done is introduced to record whether the system has successfully switched to the suspend console via vt_move_to_console() during suspend. If the switch was completed, vt_switch_done is set to 1. Later during resume, this flag is checked to ensure that the original console is restored properly by calling vt_move_to_console(orig_fgconsole, 0). This prevents scenarios where the resume logic skips console restoration due to incorrect detection of the console state, especially when a monitor is reconnected before waking up. Signed-off-by: tuhaowen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 3e7e5ad commit 4266e8f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kernel/power/console.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
1717

1818
static int orig_fgconsole, orig_kmsg;
19+
static bool vt_switch_done;
1920

2021
static DEFINE_MUTEX(vt_switch_mutex);
2122

@@ -136,17 +137,21 @@ void pm_prepare_console(void)
136137
if (orig_fgconsole < 0)
137138
return;
138139

140+
vt_switch_done = true;
141+
139142
orig_kmsg = vt_kmsg_redirect(SUSPEND_CONSOLE);
140143
return;
141144
}
142145

143146
void pm_restore_console(void)
144147
{
145-
if (!pm_vt_switch())
148+
if (!pm_vt_switch() && !vt_switch_done)
146149
return;
147150

148151
if (orig_fgconsole >= 0) {
149152
vt_move_to_console(orig_fgconsole, 0);
150153
vt_kmsg_redirect(orig_kmsg);
151154
}
155+
156+
vt_switch_done = false;
152157
}

0 commit comments

Comments
 (0)