You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/09/24 02:01:38 UTC

[incubator-nuttx] 02/02: risc-v/esp32-c3: fix pid initiatialization on esp32c3_rt_timer.c

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/incubator-nuttx.git

commit 9c2c5d39194cdfa00990a413da00306ba53854fe
Author: Sara Souza <sa...@espressif.com>
AuthorDate: Thu Sep 23 11:27:06 2021 -0300

    risc-v/esp32-c3: fix pid initiatialization on esp32c3_rt_timer.c
    
    pid variable was initialized to -EINVAL to prevent rt_timer_deinit
    from delete an invalid kthread. But priv->pid was being overwritten in the
    rt_timer_init, so in case of failure to create a kthread, it would
    call rt_timer_deinit with a non expected initialization value.
---
 arch/risc-v/src/esp32c3/esp32c3_rt_timer.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c b/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c
index 8c3cfdf..c703bab 100644
--- a/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c
+++ b/arch/risc-v/src/esp32c3/esp32c3_rt_timer.c
@@ -718,21 +718,23 @@ int esp32c3_rt_timer_init(void)
 
   nxsem_init(&priv->toutsem, 0, 0);
 
-  priv->pid = kthread_create(RT_TIMER_TASK_NAME,
+  pid = kthread_create(RT_TIMER_TASK_NAME,
                        RT_TIMER_TASK_PRIORITY,
                        RT_TIMER_TASK_STACK_SIZE,
                        rt_timer_thread,
                        NULL);
-  if (priv->pid < 0)
+  if (pid < 0)
     {
       tmrerr("ERROR: Failed to create RT timer task error=%d\n", pid);
       esp32c3_tim_deinit(priv->timer);
-      return priv->pid;
+      return pid;
     }
 
   list_initialize(&priv->runlist);
   list_initialize(&priv->toutlist);
 
+  priv->pid = pid;
+
   flags = enter_critical_section();
 
   /* ESP32-C3 hardware timer configuration: