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

commit ceb23153c38273152ec78be1ba1f28f071d089c7
Author: hujun5 <[email protected]>
AuthorDate: Wed Aug 13 20:15:02 2025 +0800

    sem_rw.c: coverity HIS_metric_violation: RETURN
    
    This change consolidates multiple return statements in down_write_trylock()
    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/semaphore/sem_rw.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sched/semaphore/sem_rw.c b/sched/semaphore/sem_rw.c
index 1c2a34ad6d5..955bf84815c 100644
--- a/sched/semaphore/sem_rw.c
+++ b/sched/semaphore/sem_rw.c
@@ -205,23 +205,26 @@ out:
 int down_write_trylock(FAR rw_semaphore_t *rwsem)
 {
   pid_t tid = _SCHED_GETTID();
+  int ret = 1;
 
   nxmutex_lock(&rwsem->protected);
 
   if (rwsem->reader > 0 || (rwsem->writer > 0 && tid != rwsem->holder))
     {
       nxmutex_unlock(&rwsem->protected);
-      return 0;
+      ret = 0;
     }
+  else
+    {
+      /* The check passes, then we just need the writer reference + 1 */
 
-  /* The check passes, then we just need the writer reference + 1 */
-
-  rwsem->writer++;
-  rwsem->holder = tid;
+      rwsem->writer++;
+      rwsem->holder = tid;
 
-  nxmutex_unlock(&rwsem->protected);
+      nxmutex_unlock(&rwsem->protected);
+    }
 
-  return 1;
+  return ret;
 }
 
 /****************************************************************************

Reply via email to