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

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


The following commit(s) were added to refs/heads/master by this push:
     new e736f247788 sched/sporadic: clear policy flag when stopping sporadic 
scheduling
e736f247788 is described below

commit e736f247788d1e7493228e1146759103e89beabb
Author: yushuailong <[email protected]>
AuthorDate: Wed Aug 26 16:52:01 2026 +0800

    sched/sporadic: clear policy flag when stopping sporadic scheduling
    
    nxsched_stop_sporadic() freed tcb->sporadic but left
    TCB_FLAG_SCHED_SPORADIC set in tcb->flags.  On thread exit,
    nxtask_recover() calls nxsched_stop_sporadic() and the final context
    switch in up_exit() then sees the stale SPORADIC policy flag and calls
    nxsched_suspend_sporadic() on a TCB whose sporadic state is already
    freed, tripping DEBUGASSERT(tcb->sporadic) and hanging the system
    (reproduced by ostest sporadic_test on sim, present on master).
    
    Clear the policy bits inside nxsched_stop_sporadic() so every caller
    leaves the TCB in a consistent state.
    
    Signed-off-by: yushuailong <[email protected]>
---
 sched/sched/sched_sporadic.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sched/sched/sched_sporadic.c b/sched/sched/sched_sporadic.c
index b9b60272b92..9991ae3d398 100644
--- a/sched/sched/sched_sporadic.c
+++ b/sched/sched/sched_sporadic.c
@@ -731,6 +731,7 @@ FAR struct replenishment_s *
       for (i = 0; i < sporadic->max_repl; i++)
         {
           FAR struct replenishment_s *tmp = &sporadic->replenishments[i];
+
           if ((tmp->flags & SPORADIC_FLAG_ALLOCED) == 0)
             {
               repl        = tmp;
@@ -889,6 +890,12 @@ int nxsched_stop_sporadic(FAR struct tcb_s *tcb)
 
   kmm_free(tcb->sporadic);
   tcb->sporadic = NULL;
+
+  /* The policy flag must not outlive the freed sporadic state: the final
+   * context switch on thread exit would dereference it.
+   */
+
+  tcb->flags &= ~TCB_FLAG_POLICY_MASK;
   return OK;
 }
 

Reply via email to