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

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

commit d1c45f7c4ea57b6a8ef6fffdd8b34cb60f12b74a
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Thu Jan 15 19:34:26 2026 +0800

    sched/hrtimer: Fix delay in hrtimer_process.
    
    This commit fixed the overflow check and renamed the period to delay, since 
the callback return value is the next delay not the period.
    
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 sched/hrtimer/hrtimer_process.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/sched/hrtimer/hrtimer_process.c b/sched/hrtimer/hrtimer_process.c
index 505084731d4..fec19050471 100644
--- a/sched/hrtimer/hrtimer_process.c
+++ b/sched/hrtimer/hrtimer_process.c
@@ -74,7 +74,7 @@ void hrtimer_process(uint64_t now)
   irqstate_t flags;
   hrtimer_entry_t func;
   uint64_t expired;
-  uint64_t period;
+  uint64_t delay;
   int cpu = this_cpu();
 
   /* Acquire the lock and seize the ownership of the hrtimer queue. */
@@ -104,7 +104,12 @@ void hrtimer_process(uint64_t now)
 
       /* Invoke the timer callback */
 
-      period = func(hrtimer, expired);
+      delay = func(hrtimer, expired);
+
+      /* Ensure the delay is valid. */
+
+      DEBUGASSERT(HRTIMER_TIME_BEFORE_EQ(expired + delay,
+                                         now + HRTIMER_MAX_DELAY));
 
       /* Re-enter critical section to update timer state */
 
@@ -115,15 +120,10 @@ void hrtimer_process(uint64_t now)
        * re-insert into the timer queue.
        */
 
-      if (period != 0u && hrtimer_is_running(hrtimer, cpu))
+      if (delay != 0u && hrtimer_is_running(hrtimer, cpu))
         {
-          hrtimer->expired = expired + period;
-
-          /* Ensure no overflow occurs */
-
-          DEBUGASSERT(hrtimer->expired >= period);
-
-          hrtimer->func = func;
+          hrtimer->expired = expired + delay;
+          hrtimer->func    = func;
           hrtimer_insert(hrtimer);
         }
 

Reply via email to