Skip to contentSkip to conversation

PM: hibernate: Add error handling for syscore_suspend()

PATCH In review Wentao Liang 2 participants 2 messages Jan 19, 2025 – Jan 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: hibernate: Add error handling for syscore_suspend()

In hibernation_platform_enter(), the code did not check the return value of syscore_suspend(), potentially leading to a situation where syscore_resume() would be called even if syscore_suspend() failed. This could cause unpredictable behavior or system instability.

This commit modifies the suspend/resume sequence to properly handle errors returned by syscore_suspend(). If an error occurs during the suspend process, the code now jumps to 'Enable_irqs' label, skipping the resume call, and only enabling interrupts after setting the system state to SYSTEM_RUNNING.

Fixes 40dc166cb5dd ("PM / Core: Introduce struct syscore_ops for core subsystems PM")
---
 kernel/power/hibernate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/power/hibernate.c +6 -1
index 1f87aa01ba44..8e5702811732 100644
@@ -608,7 +608,11 @@ int hibernation_platform_enter(void)
 
 	local_irq_disable();
 	system_state = SYSTEM_SUSPEND;
-	syscore_suspend();
+
+	error = syscore_suspend();
+	if (error)
+		goto Enable_irqs;
+
 	if (pm_wakeup_pending()) {
 		error = -EAGAIN;
 		goto Power_up;
@@ -620,6 +624,7 @@ int hibernation_platform_enter(void)
 
  Power_up:
 	syscore_resume();
+ Enable_irqs:
 	system_state = SYSTEM_RUNNING;
 	local_irq_enable();
 
Signature · 1 line
2.42.0.windows.2
#1 lore raw
Quoted 37 lines · Wentao Liang

In hibernation_platform_enter(), the code did not check the return value of syscore_suspend(), potentially leading to a situation where syscore_resume() would be called even if syscore_suspend() failed. This could cause unpredictable behavior or system instability.

This commit modifies the suspend/resume sequence to properly handle errors returned by syscore_suspend(). If an error occurs during the suspend process, the code now jumps to 'Enable_irqs' label, skipping the resume call, and only enabling interrupts after setting the system state to SYSTEM_RUNNING.

Fixes 40dc166cb5dd ("PM / Core: Introduce struct syscore_ops for core subsystems PM")
---
 kernel/power/hibernate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/power/hibernate.c +5 -1
index 1f87aa01ba44..8e5702811732 100644
@@ -608,7 +608,11 @@ int hibernation_platform_enter(void)
 
        local_irq_disable();
        system_state = SYSTEM_SUSPEND;
-       syscore_suspend();
+
+       error = syscore_suspend();
+       if (error)
+               goto Enable_irqs;
+
        if (pm_wakeup_pending()) {
                error = -EAGAIN;
                goto Power_up;

kernel/power/hibernate.c int hibernation_platform_enter(void)

Quoted 8 lines
kernel/power/hibernate.c +1 -1
@@ -620,6 +624,7 @@ int hibernation_platform_enter(void)
 
  Power_up:
        syscore_resume();
+ Enable_irqs:
        system_state = SYSTEM_RUNNING;
        local_irq_enable();
 
--

Applied (with some edits in the changelog) as 6.14-rc material, thanks!