You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ji...@apache.org on 2026/02/02 05:21:31 UTC

(nuttx) branch master updated (95ef6753ad2 -> 7801c46a0dd)

This is an automated email from the ASF dual-hosted git repository.

jiuzhudong pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


    from 95ef6753ad2 arm64/irq.h: Fix the issue of including incorrect order
     new 32001856651 sem_rw.c: coverity HIS_metric_violation: RETURN
     new 437cdfac8de sem_rw.c: coverity: HIS_metric_violation(HIS_GOTO)
     new 7801c46a0dd sem_rw.c: down_read_trylock coverity HIS_metric_violation: RETURN

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 sched/semaphore/sem_rw.c | 85 ++++++++++++++++++++++++------------------------
 1 file changed, 42 insertions(+), 43 deletions(-)


(nuttx) 01/03: sem_rw.c: coverity HIS_metric_violation: RETURN

Posted by ji...@apache.org.
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

commit 32001856651f8e0b78161105f44de2e5e9475ec3
Author: hujun5 <hu...@xiaomi.com>
AuthorDate: Wed Aug 13 13:29:50 2025 +0800

    sem_rw.c: coverity HIS_metric_violation: RETURN
    
    This change consolidates multiple return statements in init_rwsem() into a
    single exit point by inverting error conditions and restructuring nested
    if-else blocks for MISRA HIS compliance.
    
    Signed-off-by: hujun5 <hu...@xiaomi.com>
---
 sched/semaphore/sem_rw.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/sched/semaphore/sem_rw.c b/sched/semaphore/sem_rw.c
index 955bf84815c..105710a1bb5 100644
--- a/sched/semaphore/sem_rw.c
+++ b/sched/semaphore/sem_rw.c
@@ -333,29 +333,29 @@ void downgrade_write(FAR rw_semaphore_t *rwsem)
 
 int init_rwsem(FAR rw_semaphore_t *rwsem)
 {
-  int ret;
+  int ret = OK;
 
   /* Initialize structure information */
 
   ret = nxmutex_init(&rwsem->protected);
-  if (ret < 0)
+  if (ret >= 0)
     {
-      return ret;
-    }
-
-  ret = nxsem_init(&rwsem->waiting, 0, 0);
-  if (ret < 0)
-    {
-      nxmutex_destroy(&rwsem->protected);
-      return ret;
+      ret = nxsem_init(&rwsem->waiting, 0, 0);
+      if (ret >= 0)
+        {
+          rwsem->reader = 0;
+          rwsem->writer = 0;
+          rwsem->waiter = 0;
+          rwsem->holder = RWSEM_NO_HOLDER;
+          ret = OK;
+        }
+      else
+        {
+          nxmutex_destroy(&rwsem->protected);
+        }
     }
 
-  rwsem->reader = 0;
-  rwsem->writer = 0;
-  rwsem->waiter = 0;
-  rwsem->holder = RWSEM_NO_HOLDER;
-
-  return OK;
+  return ret;
 }
 
 /****************************************************************************


(nuttx) 02/03: sem_rw.c: coverity: HIS_metric_violation(HIS_GOTO)

Posted by ji...@apache.org.
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

commit 437cdfac8de70c6487b2f76f514dfcd4a2da54ab
Author: hujun5 <hu...@xiaomi.com>
AuthorDate: Thu Aug 14 19:25:21 2025 +0800

    sem_rw.c: coverity: HIS_metric_violation(HIS_GOTO)
    
    This change replaces goto-based control flow with structured if-else blocks
    in the down_read() function to comply with MISRA HIS coding standards while
    maintaining identical functional behavior.
    
    Signed-off-by: hujun5 <hu...@xiaomi.com>
---
 sched/semaphore/sem_rw.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/sched/semaphore/sem_rw.c b/sched/semaphore/sem_rw.c
index 105710a1bb5..7aa8e05be74 100644
--- a/sched/semaphore/sem_rw.c
+++ b/sched/semaphore/sem_rw.c
@@ -123,25 +123,25 @@ void down_read(FAR rw_semaphore_t *rwsem)
   if (rwsem->holder == _SCHED_GETTID())
     {
       rwsem->writer++;
-      goto out;
     }
-
-  while (rwsem->writer > 0)
+  else
     {
-      rwsem->waiter++;
-      nxmutex_unlock(&rwsem->protected);
-      nxsem_wait(&rwsem->waiting);
-      nxmutex_lock(&rwsem->protected);
-      rwsem->waiter--;
-    }
+      while (rwsem->writer > 0)
+        {
+          rwsem->waiter++;
+          nxmutex_unlock(&rwsem->protected);
+          nxsem_wait(&rwsem->waiting);
+          nxmutex_lock(&rwsem->protected);
+          rwsem->waiter--;
+        }
 
-  /* In a scenario where there is no write lock, we just need to make the
-   * read base +1.
-   */
+      /* In a scenario where there is no write lock, we just need to make the
+       * read base +1.
+       */
 
-  rwsem->reader++;
+      rwsem->reader++;
+    }
 
-out:
   nxmutex_unlock(&rwsem->protected);
 }
 


(nuttx) 03/03: sem_rw.c: down_read_trylock coverity HIS_metric_violation: RETURN

Posted by ji...@apache.org.
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

commit 7801c46a0dd49b8a4cb81ddcaa4fd850681044b6
Author: hujun5 <hu...@xiaomi.com>
AuthorDate: Wed Aug 13 20:28:23 2025 +0800

    sem_rw.c: down_read_trylock coverity HIS_metric_violation: RETURN
    
    This change consolidates multiple return statements in down_read_trylock() into
    a single exit point and replaces goto with if-else structure to reduce cyclomatic
    complexity and comply with MISRA HIS coding standards.
    
    Signed-off-by: hujun5 <hu...@xiaomi.com>
---
 sched/semaphore/sem_rw.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/sched/semaphore/sem_rw.c b/sched/semaphore/sem_rw.c
index 7aa8e05be74..a79ce0c0848 100644
--- a/sched/semaphore/sem_rw.c
+++ b/sched/semaphore/sem_rw.c
@@ -65,6 +65,8 @@ static inline void up_wait(FAR rw_semaphore_t *rwsem)
 
 int down_read_trylock(FAR rw_semaphore_t *rwsem)
 {
+  int ret = 1;
+
   nxmutex_lock(&rwsem->protected);
 
   /* if the write lock is already held by oneself and since the write lock
@@ -75,25 +77,22 @@ int down_read_trylock(FAR rw_semaphore_t *rwsem)
   if (rwsem->holder == _SCHED_GETTID())
     {
       rwsem->writer++;
-      goto out;
     }
-
-  if (rwsem->writer > 0)
+  else if (rwsem->writer > 0)
     {
-      nxmutex_unlock(&rwsem->protected);
-      return 0;
+      ret = 0;
     }
+  else
+    {
+      /* In a scenario where there is no write lock, we just need to
+       * make the read base +1.
+       */
 
-  /* In a scenario where there is no write lock, we just need to make the
-   * read base +1.
-   */
-
-  rwsem->reader++;
+      rwsem->reader++;
+    }
 
-out:
   nxmutex_unlock(&rwsem->protected);
-
-  return 1;
+  return ret;
 }
 
 /****************************************************************************