PM: hibernate: Add error handling for syscore_suspend()
Subsystems (2)
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.
--- kernel/power/hibernate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/power/hibernate.c +6 -1
@@ -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
Rafael J. Wysocki
maintainerQuoted 37 lines · Wentao Liang
In
hibernation_platform_enter(), the code did not check the return value ofsyscore_suspend(), potentially leading to a situation wheresyscore_resume()would be called even ifsyscore_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 toSYSTEM_RUNNING.Fixes 40dc166cb5dd ("PM / Core: Introduce struct syscore_ops for core subsystems PM")Signed-off-by Wentao Liang <[email protected]>--- kernel/power/hibernate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)kernel/power/hibernate.c +5
-1@@ -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!