This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 15d68cab467ced9f21399dc3259c1287be5f1a34
Author: Honghao Xiang <[email protected]>
AuthorDate: Fri Nov 27 02:58:06 2026 +0000

    power: pm: treat any non-OK pm_changestate() return as failure
    
    ## Summary
    
    `pm_changestate()` returns the PM state on success in some paths and a 
negative errno on failure, but the three call sites in `pm_idle()` test `ret < 
0`. A positive non-`OK` return is therefore treated as success and the failed 
transition is not rolled back.
    
    Compare against `OK` instead, so any non-success return restores the 
previous state.
    
    ## Testing
    
    Source-level: all three sites are the only consumers of the 
`pm_changestate()` return value inside `pm_idle()`; the `newstate = oldstate` / 
`PM_NORMAL` rollbacks are unchanged for the failure path.
    
    Issue reference: #22209.
    
    Signed-off-by: Honghao Xiang <[email protected]>
---
 drivers/power/pm/pm_idle.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/pm/pm_idle.c b/drivers/power/pm/pm_idle.c
index 8ffe82afd4f..d8c85436d91 100644
--- a/drivers/power/pm/pm_idle.c
+++ b/drivers/power/pm/pm_idle.c
@@ -158,7 +158,7 @@ void pm_idle(pm_idle_handler_t handler)
   newstate = pm_checkstate(domain);
 
   ret = pm_changestate(domain, newstate);
-  if (ret < 0)
+  if (ret != OK)
     {
       newstate = oldstate;
     }
@@ -185,7 +185,7 @@ void pm_idle(pm_idle_handler_t handler)
     {
       systemstate = pm_checkstate(PM_IDLE_DOMAIN);
       ret         = pm_changestate(PM_IDLE_DOMAIN, systemstate);
-      if (ret < 0)
+      if (ret != OK)
         {
           systemstate = PM_NORMAL;
         }
@@ -241,7 +241,7 @@ void pm_idle(pm_idle_handler_t handler)
 
   newstate = pm_checkstate(PM_IDLE_DOMAIN);
   ret      = pm_changestate(PM_IDLE_DOMAIN, newstate);
-  if (ret < 0)
+  if (ret != OK)
     {
       newstate = PM_NORMAL;
     }

Reply via email to