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 0f5b9bbfac70cf898e69a428de119112fd8f8684
Author: pangzhen1 <[email protected]>
AuthorDate: Tue Sep 30 09:54:39 2025 +0800

    sched/tls: functions should have exactly one exit point
    
    Fix Coverity: every function should have exactly one entry point and
    one exit point (MISRA C-2004 Rule 14.7).  Replace the early
    "return -ENOMEM" in task_init_info(), tls_dup_info() and
    tls_init_info() with a single return of ret.  No functional change.
    
    Signed-off-by: pangzhen1 <[email protected]>
---
 sched/tls/task_initinfo.c | 26 +++++++++++++++-----------
 sched/tls/tls_dupinfo.c   | 35 +++++++++++++++++++----------------
 sched/tls/tls_initinfo.c  | 37 ++++++++++++++++++++-----------------
 3 files changed, 54 insertions(+), 44 deletions(-)

diff --git a/sched/tls/task_initinfo.c b/sched/tls/task_initinfo.c
index 3155848b923..9f31426e217 100644
--- a/sched/tls/task_initinfo.c
+++ b/sched/tls/task_initinfo.c
@@ -110,6 +110,7 @@ static void task_init_stream(FAR struct streamlist *list)
 int task_init_info(FAR struct task_group_s *group)
 {
   FAR struct task_info_s *info;
+  int ret = OK;
 
   /* Allocate task info for group */
 
@@ -117,33 +118,36 @@ int task_init_info(FAR struct task_group_s *group)
   info = group_zalloc(group, sizeof(struct task_info_s));
   if (info == NULL)
     {
-      return -ENOMEM;
+      ret = -ENOMEM;
     }
 #else
   info = &group->tg_info_;
 #endif
 
-  /* Initialize user space mutex */
+  if (ret == OK)
+    {
+      /* Initialize user space mutex */
 
-  nxrmutex_init(&info->ta_lock);
-  group->tg_info = info;
+      nxrmutex_init(&info->ta_lock);
+      group->tg_info = info;
 
 #ifdef CONFIG_PTHREAD_ATFORK
-  list_initialize(&info->ta_atfork);
+      list_initialize(&info->ta_atfork);
 #endif
 
 #if defined(CONFIG_LIBC_ELF) || defined(CONFIG_BINFMT_LOADABLE)
-  /* The ELF objects that the task group loads with dlopen() */
+      /* The ELF objects that the task group loads with dlopen() */
 
-  nxrmutex_init(&info->ta_modlock);
-  list_initialize(&info->ta_modules);
+      nxrmutex_init(&info->ta_modlock);
+      list_initialize(&info->ta_modules);
 #endif
 
 #ifdef CONFIG_FILE_STREAM
-  /* Initialize file streams for the task group */
+      /* Initialize file streams for the task group */
 
-  task_init_stream(&info->ta_streamlist);
+      task_init_stream(&info->ta_streamlist);
 #endif
+    }
 
-  return OK;
+  return ret;
 }
diff --git a/sched/tls/tls_dupinfo.c b/sched/tls/tls_dupinfo.c
index e71185b87e1..5cb43fa4c01 100644
--- a/sched/tls/tls_dupinfo.c
+++ b/sched/tls/tls_dupinfo.c
@@ -52,40 +52,43 @@
 int tls_dup_info(FAR struct tcb_s *dst, FAR struct tcb_s *src)
 {
   FAR struct tls_info_s *info;
+  int ret = OK;
 
   /* Allocate thread local storage */
 
   info = up_stack_frame(dst, tls_info_size());
   if (info == NULL)
     {
-      return -ENOMEM;
+      ret = -ENOMEM;
     }
+  else
+    {
+      DEBUGASSERT(info == dst->stack_alloc_ptr);
 
-  DEBUGASSERT(info == dst->stack_alloc_ptr);
-
-  /* Copy thread local storage */
+      /* Copy thread local storage */
 
-  memcpy(info, src->stack_alloc_ptr, tls_info_size());
+      memcpy(info, src->stack_alloc_ptr, tls_info_size());
 
-  /* Attach per-task info in group to TLS */
+      /* Attach per-task info in group to TLS */
 
-  info->tl_task = dst->group->tg_info;
+      info->tl_task = dst->group->tg_info;
 
-  /* Initialize the starting address of argv to NULL to prevent
-   * it from being misused.
-   */
+      /* Initialize the starting address of argv to NULL to prevent
+       * it from being misused.
+       */
 
-  info->tl_argv = NULL;
+      info->tl_argv = NULL;
 
 #ifdef CONFIG_TLS_EMUTLS
-  /* The parent's copies of the __thread variables stay with the parent */
+      /* The parent's copies of the __thread variables stay with the parent */
 
-  info->tl_emutls = NULL;
+      info->tl_emutls = NULL;
 #endif
 
-  /* Thread ID */
+      /* Thread ID */
 
-  info->tl_tid = dst->pid;
+      info->tl_tid = dst->pid;
+    }
 
-  return OK;
+  return ret;
 }
diff --git a/sched/tls/tls_initinfo.c b/sched/tls/tls_initinfo.c
index 0ba7c9c8d8c..af3d2213d94 100644
--- a/sched/tls/tls_initinfo.c
+++ b/sched/tls/tls_initinfo.c
@@ -50,39 +50,42 @@
 int tls_init_info(FAR struct tcb_s *tcb)
 {
   FAR struct tls_info_s *info;
+  int ret = OK;
 
   /* Allocate thread local storage */
 
   info = up_stack_frame(tcb, tls_info_size());
   if (info == NULL)
     {
-      return -ENOMEM;
+      ret = -ENOMEM;
     }
+  else
+    {
+      DEBUGASSERT(info == tcb->stack_alloc_ptr);
 
-  DEBUGASSERT(info == tcb->stack_alloc_ptr);
-
-  /* Initialize thread local storage */
+      /* Initialize thread local storage */
 
-  up_tls_initialize(info);
+      up_tls_initialize(info);
 
-  /* Derive tl_size w/o arch knowledge */
+      /* Derive tl_size w/o arch knowledge */
 
-  info->tl_size = (uint16_t)((FAR char *)tcb->stack_base_ptr -
-                             (FAR char *)tcb->stack_alloc_ptr);
+      info->tl_size = (uint16_t)((FAR char *)tcb->stack_base_ptr -
+                                 (FAR char *)tcb->stack_alloc_ptr);
 
-  /* Attach per-task info in group to TLS */
+      /* Attach per-task info in group to TLS */
 
-  info->tl_task = tcb->group->tg_info;
+      info->tl_task = tcb->group->tg_info;
 
-  /* Thread ID */
+      /* Thread ID */
 
-  info->tl_tid = tcb->pid;
+      info->tl_tid = tcb->pid;
 
-  /* Initialize the starting address of argv to NULL to prevent
-   * it from being misused.
-   */
+      /* Initialize the starting address of argv to NULL to prevent
+       * it from being misused.
+       */
 
-  info->tl_argv = NULL;
+      info->tl_argv = NULL;
+    }
 
-  return OK;
+  return ret;
 }

Reply via email to