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 e443b298fb84d017813a50e9787461190dc77826 Author: haopengxiang <[email protected]> AuthorDate: Sat Apr 11 16:26:42 2026 +0800 spinlock: fix uninitialized ret in rspin_trylock rspin_trylock() has three branches: 1. Lock owned by this CPU -> ret = true 2. Lock free (old_val == 0) -> ret = CAS result 3. Lock owned by other CPU -> ret is uninitialized Branch 3 is reachable when another CPU holds the lock, but ret is never assigned in this path. This causes undefined behavior and a compile error with clang -Wsometimes-uninitialized. The bug was introduced in commit 7133388 ("spinlock: Improve the performance of rspinlock") which refactored rspin_trylock and changed "bool ret = false" to "bool ret", losing the default initialization. The paired function rspin_unlock() in the same commit correctly kept "bool ret = false", confirming this was an oversight rather than a deliberate optimization. Fix by restoring the "= false" initializer, which is the correct return value for trylock failure (lock held by another CPU). Assisted-By: mimo-v2.6-pro Signed-off-by: pengxianghao <[email protected]> --- include/nuttx/spinlock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index a874f5e58e5..4e51d7175c0 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -644,7 +644,7 @@ irqstate_t rspin_lock_irqsave_nopreempt(FAR rspinlock_t *lock) SPINLOCK_INLINE bool rspin_trylock(FAR rspinlock_t *lock) { uint32_t old_val; - bool ret; + bool ret = false; uint32_t owner = (uint32_t)this_cpu() + 1u; /* Already owned this lock. */
