Skip to content

Commit 0c4cae1

Browse files
Chris Fengrafaeljw
authored andcommitted
PM: hibernate: Avoid missing wakeup events during hibernation
Wakeup events that occur in the hibernation process's hibernation_platform_enter() cannot wake up the system. Although the current hibernation framework will execute part of the recovery process after a wakeup event occurs, it ultimately performs a shutdown operation because the system does not check the return value of hibernation_platform_enter(). In short, if a wakeup event occurs before putting the system into the final low-power state, it will be missed. To solve this problem, check the return value of hibernation_platform_enter(). When it returns -EAGAIN or -EBUSY (indicate the occurrence of a wakeup event), execute the hibernation recovery process, discard the previously saved image, and ultimately return to the working state. Signed-off-by: Chris Feng <[email protected]> [ rjw: Rephrase the message printed when going back to the working state ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 4ac934b commit 0c4cae1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

kernel/power/hibernate.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,9 @@ int hibernation_platform_enter(void)
642642
*/
643643
static void power_down(void)
644644
{
645-
#ifdef CONFIG_SUSPEND
646645
int error;
647646

647+
#ifdef CONFIG_SUSPEND
648648
if (hibernation_mode == HIBERNATION_SUSPEND) {
649649
error = suspend_devices_and_enter(mem_sleep_current);
650650
if (error) {
@@ -667,7 +667,13 @@ static void power_down(void)
667667
kernel_restart(NULL);
668668
break;
669669
case HIBERNATION_PLATFORM:
670-
hibernation_platform_enter();
670+
error = hibernation_platform_enter();
671+
if (error == -EAGAIN || error == -EBUSY) {
672+
swsusp_unmark();
673+
events_check_enabled = false;
674+
pr_info("Wakeup event detected during hibernation, rolling back.\n");
675+
return;
676+
}
671677
fallthrough;
672678
case HIBERNATION_SHUTDOWN:
673679
if (kernel_can_power_off())

kernel/power/power.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ extern int swsusp_write(unsigned int flags);
175175
void swsusp_close(void);
176176
#ifdef CONFIG_SUSPEND
177177
extern int swsusp_unmark(void);
178+
#else
179+
static inline int swsusp_unmark(void) { return 0; }
178180
#endif
179181

180182
struct __kernel_old_timeval;

0 commit comments

Comments
 (0)