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 df07a1d5d53cd534d4521ee9c65db031a44cb81a
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Thu May 28 14:08:09 2026 +0800

    spinlock: Fix Coverity CONSTANT_EXPRESSION_RESULT in rspin_lock
    
    RSPINLOCK_COUNT(old_val + 1u) expands to
    ((uint32_t)(old_val + 1U) & 0xffffU) <= 0xffff which is always true,
    making the DEBUGASSERT ineffective.
    
    Change to RSPINLOCK_COUNT(old_val) + 1u so the check correctly validates
    that the 16-bit count field will not overflow when incremented.
    
    Assisted-By: mimo-v2.6-pro
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 include/nuttx/spinlock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h
index ac91620eed8..a49acebecf4 100644
--- a/include/nuttx/spinlock.h
+++ b/include/nuttx/spinlock.h
@@ -550,7 +550,7 @@ void rspin_lock(FAR rspinlock_t *lock)
 
   if (RSPINLOCK_OWNER(old_val) == owner)
     {
-      DEBUGASSERT(RSPINLOCK_COUNT(old_val + 1u) <= UINT16_MAX);
+      DEBUGASSERT(RSPINLOCK_COUNT(old_val) + 1u <= UINT16_MAX);
 
       lock->local_val = old_val + 1u;
     }
@@ -633,7 +633,7 @@ static inline_function bool rspin_trylock(FAR rspinlock_t 
*lock)
 
   if (RSPINLOCK_OWNER(old_val) == owner)
     {
-      DEBUGASSERT(RSPINLOCK_COUNT(old_val + 1u) <= UINT16_MAX);
+      DEBUGASSERT(RSPINLOCK_COUNT(old_val) + 1u <= UINT16_MAX);
 
       lock->local_val = old_val + 1u;
       ret = true;

Reply via email to