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


The following commit(s) were added to refs/heads/master by this push:
     new 9ae2fce3c11 sched_getparam.c: coverity HIS_metric_violation: RETURN
9ae2fce3c11 is described below

commit 9ae2fce3c1198d4c8779b370de2c2e0286cd54aa
Author: hujun5 <[email protected]>
AuthorDate: Wed Jan 28 14:16:59 2026 +0800

    sched_getparam.c: coverity HIS_metric_violation: RETURN
    
    This change consolidates multiple return statements in nxsched_get_param()
    into a single exit point and restructures the error handling path to reduce
    cyclomatic complexity and comply with MISRA HIS coding standards.
    
    Signed-off-by: hujun5 <[email protected]>
---
 sched/sched/sched_getparam.c | 95 ++++++++++++++++++++++----------------------
 1 file changed, 48 insertions(+), 47 deletions(-)

diff --git a/sched/sched/sched_getparam.c b/sched/sched/sched_getparam.c
index 368546598b1..7232134e2cb 100644
--- a/sched/sched/sched_getparam.c
+++ b/sched/sched/sched_getparam.c
@@ -77,70 +77,71 @@ int nxsched_get_param(pid_t pid, FAR struct sched_param 
*param)
 
   if (param == NULL)
     {
-      return -EINVAL;
+      ret = -EINVAL;
     }
-
-  /* Check if the task to restart is the calling task */
-
-  rtcb = this_task();
-  if (pid == 0 || pid == rtcb->pid)
-    {
-      /* Return the priority if the calling task. */
-
-      param->sched_priority = (int)rtcb->sched_priority;
-    }
-
-  /* This PID is not for the calling task, we will have to look it up */
-
   else
     {
-      /* Get the TCB associated with this PID */
+      /* Check if the task to restart is the calling task */
 
-      flags = enter_critical_section();
-      tcb = nxsched_get_tcb(pid);
-      if (!tcb)
+      rtcb = this_task();
+      if (pid == 0 || pid == rtcb->pid)
         {
-          /* This PID does not correspond to any known task */
+          /* Return the priority if the calling task. */
 
-          ret = -ESRCH;
+          param->sched_priority = (int)rtcb->sched_priority;
         }
+
+      /* This PID is not for the calling task, we will have to look it up */
+
       else
         {
-#ifdef CONFIG_SCHED_SPORADIC
-#endif
-          /* Return the priority of the task */
+          /* Get the TCB associated with this PID */
 
-          param->sched_priority = (int)tcb->sched_priority;
-
-#ifdef CONFIG_SCHED_SPORADIC
-          if ((tcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC)
+          flags = enter_critical_section();
+          tcb = nxsched_get_tcb(pid);
+          if (!tcb)
             {
-              FAR struct sporadic_s *sporadic = tcb->sporadic;
-              DEBUGASSERT(sporadic != NULL);
-
-              /* Return parameters associated with SCHED_SPORADIC */
+              /* This PID does not correspond to any known task */
 
-              param->sched_ss_low_priority = (int)sporadic->low_priority;
-              param->sched_ss_max_repl     = (int)sporadic->max_repl;
-
-              clock_ticks2time(&param->sched_ss_repl_period,
-                               sporadic->repl_period);
-              clock_ticks2time(&param->sched_ss_init_budget,
-                               sporadic->budget);
+              ret = -ESRCH;
             }
           else
             {
-              param->sched_ss_low_priority        = 0;
-              param->sched_ss_max_repl            = 0;
-              param->sched_ss_repl_period.tv_sec  = 0;
-              param->sched_ss_repl_period.tv_nsec = 0;
-              param->sched_ss_init_budget.tv_sec  = 0;
-              param->sched_ss_init_budget.tv_nsec = 0;
-            }
+              /* Return the priority of the task */
+
+              param->sched_priority = (int)tcb->sched_priority;
+
+#ifdef CONFIG_SCHED_SPORADIC
+              if ((tcb->flags & TCB_FLAG_POLICY_MASK) ==
+                  TCB_FLAG_SCHED_SPORADIC)
+                {
+                  FAR struct sporadic_s *sporadic = tcb->sporadic;
+                  DEBUGASSERT(sporadic != NULL);
+
+                  /* Return parameters associated with SCHED_SPORADIC */
+
+                  param->sched_ss_low_priority = (int)sporadic->low_priority;
+                  param->sched_ss_max_repl     = (int)sporadic->max_repl;
+
+                  clock_ticks2time(&param->sched_ss_repl_period,
+                                  sporadic->repl_period);
+                  clock_ticks2time(&param->sched_ss_init_budget,
+                                  sporadic->budget);
+                }
+              else
+                {
+                  param->sched_ss_low_priority        = 0;
+                  param->sched_ss_max_repl            = 0;
+                  param->sched_ss_repl_period.tv_sec  = 0;
+                  param->sched_ss_repl_period.tv_nsec = 0;
+                  param->sched_ss_init_budget.tv_sec  = 0;
+                  param->sched_ss_init_budget.tv_nsec = 0;
+                }
 #endif
-        }
+            }
 
-      leave_critical_section(flags);
+          leave_critical_section(flags);
+        }
     }
 
   return ret;

Reply via email to