From 8316f097ce2ae7cd3c04dc36558ae832399a2fcb Mon Sep 17 00:00:00 2001 From: Hessel van der Molen Date: Wed, 30 Oct 2024 17:33:08 +0100 Subject: [PATCH] arch: arm: cortex_m: pm_s2ram: fix system_off rv as rv of s2ram_suspend The return value of the system_off call is overwritten by the the call to pm_s2ram_mark_check_and_clear. As arch_pm_s2ram_suspend needs to specify why system_off failed, we need to make sure the rv of system_off is moved to a safe register before calling pm_s2ram_mark_check_and_clear and moved to r0 als rv of arch_pm_s2ram_suspend when the suspend call exits. Signed-off-by: Hessel van der Molen --- arch/arm/core/cortex_m/pm_s2ram.S | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm/core/cortex_m/pm_s2ram.S b/arch/arm/core/cortex_m/pm_s2ram.S index 1a4da5ce784f89..d15bfea0432191 100644 --- a/arch/arm/core/cortex_m/pm_s2ram.S +++ b/arch/arm/core/cortex_m/pm_s2ram.S @@ -193,6 +193,9 @@ SECTION_FUNC(TEXT, arch_pm_s2ram_suspend) * not successful (in r0 the return value). */ + /* Move return value of system_off to callee-saved register. */ + mov r4, r0 + /* * Reset the marking of suspend to RAM, return is ignored. */ @@ -200,7 +203,9 @@ SECTION_FUNC(TEXT, arch_pm_s2ram_suspend) bl pm_s2ram_mark_check_and_clear mov lr, r1 - /* Move system_off back to r0 as return value */ + /* Move the stored return value of system_off back to r0, + * setting it as return value for this function. + */ mov r0, r4 POP_GPRS