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 7400a24515b619d10a9a479fa032f04231914ca8
Author: wangzhi16 <[email protected]>
AuthorDate: Tue Sep 23 16:32:05 2025 +0800

    sched/spinlock: fix bug of Debug tools for spinlock.
    
    sched/spinlock: fix bug of Debug tools for spinlock.
    
    Assisted-By: mimo-v2.6-pro
    Co-authored-by: ouyangxiangzhen <[email protected]>
    Signed-off-by: wangzhi16 <[email protected]>
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 include/nuttx/spinlock.h      | 14 +++++++-------
 include/nuttx/spinlock_type.h |  6 +++---
 sched/irq/irq_spinlock.c      |  4 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h
index c88d71fdcd8..695d98b8233 100644
--- a/include/nuttx/spinlock.h
+++ b/include/nuttx/spinlock.h
@@ -33,6 +33,7 @@
 #include <assert.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <string.h>
 #include <sched.h>
 
 #include <nuttx/compiler.h>
@@ -120,8 +121,8 @@ void spinlock_switch_context(FAR struct tcb_s *from);
  *
  ****************************************************************************/
 
-/* void spin_lock_init(FAR spinlock_t *lock); */
-#define spin_lock_init(l) do { *(l) = SP_UNLOCKED; } while (0)
+#define spin_lock_init(l) \
+   do { memset((FAR void *)l, 0, sizeof(*(l))); } while (0)
 
 /****************************************************************************
  * Name: rspin_lock_init
@@ -138,10 +139,8 @@ void spinlock_switch_context(FAR struct tcb_s *from);
  *
  ****************************************************************************/
 
-static inline_function void rspin_lock_init(FAR rspinlock_t *lock)
-{
-  *lock = RSPINLOCK_INITIALIZER;
-}
+#define rspin_lock_init(l) \
+   do { memset((FAR void *)l, 0, sizeof(*(l))); } while (0)
 
 /****************************************************************************
  * Name: spin_lock_notrace
@@ -1162,7 +1161,8 @@ void rspin_restorelock(FAR rspinlock_t *lock, uint16_t 
count)
  *
  ****************************************************************************/
 
-#define rwlock_init(l) do { (l->lock) = RW_SP_UNLOCKED; } while(0)
+#define rwlock_init(l) \
+   do { memset((FAR void *)l, 0, sizeof(*(l))); } while (0)
 
 /****************************************************************************
  * Name: read_lock
diff --git a/include/nuttx/spinlock_type.h b/include/nuttx/spinlock_type.h
index 11b950419d4..9a920ba20d9 100644
--- a/include/nuttx/spinlock_type.h
+++ b/include/nuttx/spinlock_type.h
@@ -45,12 +45,12 @@ extern "C"
 #if defined(CONFIG_SPINLOCK_DEBUG)
 typedef struct spinlock_debug_s
 {
-  FAR sq_entry_t *flink;
+  sq_entry_t flink;
   FAR struct tcb_s *holder;
   FAR void *caller;
 } spinlock_debug_t;
 #  define SPINLOCK_DEBUG_INFO spinlock_debug_t info;
-#  define SPINLOCK_DEBUG_INIT {NULL, NULL, NULL}
+#  define SPINLOCK_DEBUG_INIT {{NULL}, NULL, NULL}
 #else
 #  define SPINLOCK_DEBUG_INFO
 #  define SPINLOCK_DEBUG_INIT
@@ -102,7 +102,7 @@ typedef struct spinlock_s
 #endif /* CONFIG_SPINLOCK */
 
 #define RSPINLOCK_CPU_INVALID (-1)
-#define RSPINLOCK_INITIALIZER (rspinlock_t){{0}, SPINLOCK_DEBUG_INIT}
+#define RSPINLOCK_INITIALIZER {{0}, SPINLOCK_DEBUG_INIT}
 
 typedef struct rspinlock_s
 {
diff --git a/sched/irq/irq_spinlock.c b/sched/irq/irq_spinlock.c
index e35f4061d52..e3ba86cb5ed 100644
--- a/sched/irq/irq_spinlock.c
+++ b/sched/irq/irq_spinlock.c
@@ -85,7 +85,7 @@ void spinlock_mark_locked(FAR spinlock_debug_t *info)
 
   info->holder = rtcb;
   info->caller = return_address(0);
-  sq_addlast(info->flink, &rtcb->hold_spinlock);
+  sq_addlast(&info->flink, &rtcb->hold_spinlock);
 }
 
 void spinlock_mark_unlocked(FAR spinlock_debug_t *info)
@@ -106,7 +106,7 @@ void spinlock_mark_unlocked(FAR spinlock_debug_t *info)
    * this will pollute flags. So check if unlocking is the reverse order.
    */
 
-  if (sq_tail(&rtcb->hold_spinlock) != info->flink)
+  if (sq_tail(&rtcb->hold_spinlock) != &info->flink)
     {
       _alert("Detect thread(%d) unlocks spinlock(%p) in the wrong order!\n",
              rtcb->pid, info);

Reply via email to