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 28603335527 sched_setpriority.c: coverity HIS_metric_violation: RETURN
28603335527 is described below

commit 28603335527b29ab06d4b5030076e7f2b13ef56b
Author: hujun5 <[email protected]>
AuthorDate: Wed Jan 28 10:26:02 2026 +0800

    sched_setpriority.c: coverity HIS_metric_violation: RETURN
    
    This change consolidates multiple return statements in 
nxsched_set_priority()
    into a single exit point to reduce cyclomatic complexity and comply with 
MISRA
    HIS coding standards for safety-critical embedded systems.
    
    Signed-off-by: hujun5 <[email protected]>
---
 sched/sched/sched_setpriority.c | 66 ++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 31 deletions(-)

diff --git a/sched/sched/sched_setpriority.c b/sched/sched/sched_setpriority.c
index 11cdf855278..8bb457fd79d 100644
--- a/sched/sched/sched_setpriority.c
+++ b/sched/sched/sched_setpriority.c
@@ -262,52 +262,56 @@ static inline void nxsched_blocked_setpriority(FAR struct 
tcb_s *tcb,
 int nxsched_set_priority(FAR struct tcb_s *tcb, int sched_priority)
 {
   irqstate_t flags;
+  int ret = OK;
 
   /* Verify that the requested priority is in the valid range */
 
   if (sched_priority < SCHED_PRIORITY_MIN ||
       sched_priority > SCHED_PRIORITY_MAX)
     {
-      return -EINVAL;
+      ret = -EINVAL;
     }
+  else
+    {
+      /* We need to assure that there there is no interrupt activity while
+       * performing the following.
+       */
 
-  /* We need to assure that there there is no interrupt activity while
-   * performing the following.
-   */
+      flags = enter_critical_section();
 
-  flags = enter_critical_section();
+      /* There are three major cases (and two sub-cases) that must be
+       * considered:
+       */
 
-  /* There are three major cases (and two sub-cases) that must be
-   * considered:
-   */
+      switch (tcb->task_state)
+        {
+          /* CASE 1. The task is running and a context switch may be caused
+           * by the re-prioritization
+           */
 
-  switch (tcb->task_state)
-    {
-      /* CASE 1. The task is running and a context switch may be caused by
-       * the re-prioritization
-       */
+          case TSTATE_TASK_RUNNING:
+            nxsched_running_setpriority(tcb, sched_priority);
+            break;
 
-      case TSTATE_TASK_RUNNING:
-        nxsched_running_setpriority(tcb, sched_priority);
-        break;
+          /* CASE 2. The task is ready-to-run (but not running) and a context
+           * switch may be caused by the re-prioritization
+           */
 
-      /* CASE 2. The task is ready-to-run (but not running) and a context
-       * switch may be caused by the re-prioritization
-       */
+          case TSTATE_TASK_READYTORUN:
+            nxsched_readytorun_setpriority(tcb, sched_priority);
+            break;
 
-      case TSTATE_TASK_READYTORUN:
-        nxsched_readytorun_setpriority(tcb, sched_priority);
-        break;
+          /* CASE 3. The task is not in the ready to run list.  Changing its
+           * Priority cannot effect the currently executing task.
+           */
 
-      /* CASE 3. The task is not in the ready to run list.  Changing its
-       * Priority cannot effect the currently executing task.
-       */
+          default:
+            nxsched_blocked_setpriority(tcb, sched_priority);
+            break;
+        }
 
-      default:
-        nxsched_blocked_setpriority(tcb, sched_priority);
-        break;
-    }
+      leave_critical_section(flags);
+   }
 
-  leave_critical_section(flags);
-  return OK;
+  return ret;
 }

Reply via email to