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

xiaoxiang 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 112b8cf470 sched/task_exit.c: Refresh current CPU instead of relying 
on stale value
112b8cf470 is described below

commit 112b8cf47099330366de1e4ecb2ef7f97753bc86
Author: Ville Juven <[email protected]>
AuthorDate: Tue Oct 22 16:06:38 2024 +0300

    sched/task_exit.c: Refresh current CPU instead of relying on stale value
    
    The comment about the CPU index remaining stable is incorrect. There is no
    guarantee the task does not yield during the exit process, meaning the CPU
    can most definitely change. Also, there is no reason why it should not be
    allowed to change.
    
    This fixes a full system crash during process exit when the CPU changes
    and we query the current task from the old CPU.
---
 sched/task/task_exit.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c
index a4efb2bc83..b4bb1b8401 100644
--- a/sched/task/task_exit.c
+++ b/sched/task/task_exit.c
@@ -76,17 +76,11 @@ int nxtask_exit(void)
   FAR struct tcb_s *rtcb;
   int ret;
 #ifdef CONFIG_SMP
-  int cpu;
-
-  /* Get the current CPU.  By assumption, we are within a critical section
-   * and, hence, the CPU index will remain stable.
-   *
-   * Avoid using this_task() because it may assume a state that is not
+  /* Avoid using this_task() because it may assume a state that is not
    * appropriate for an exiting task.
    */
 
-  cpu  = this_cpu();
-  dtcb = current_task(cpu);
+  dtcb = current_task(this_cpu());
 #else
   dtcb = this_task();
 #endif
@@ -111,7 +105,7 @@ int nxtask_exit(void)
   /* Get the new task at the head of the ready to run list */
 
 #ifdef CONFIG_SMP
-  rtcb = current_task(cpu);
+  rtcb = current_task(this_cpu());
 #else
   rtcb = this_task();
 #endif

Reply via email to