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 f4c23eb88b4 boards/boardctl.c: use spinlock IRQ-safe interfaces for 
consistency
f4c23eb88b4 is described below

commit f4c23eb88b4017987a08dea3597c2562f00270d2
Author: hujun5 <[email protected]>
AuthorDate: Sun Jul 20 15:05:16 2025 +0800

    boards/boardctl.c: use spinlock IRQ-safe interfaces for consistency
    
    Replace direct up_irq_save/up_irq_restore calls with spinlock IRQ-safe
    interfaces (spin_lock_irqsave, spin_trylock_irqsave, spin_unlock_irqrestore)
    to maintain semantic consistency when both spinlock and IRQ flags are used 
together.
    
    Signed-off-by: hujun5 <[email protected]>
---
 boards/boardctl.c | 55 ++++++++++++++++++++++++++++++-------------------------
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/boards/boardctl.c b/boards/boardctl.c
index e4006aebdcb..d61a5515509 100644
--- a/boards/boardctl.c
+++ b/boards/boardctl.c
@@ -804,42 +804,47 @@ int boardctl(unsigned int cmd, uintptr_t arg)
 
           if (spinlock->action == BOARDIOC_SPINLOCK_LOCK)
             {
-              if (flags != NULL)
-                {
-                  *flags = up_irq_save();
-                }
-
               if (lock != NULL)
                 {
-                  spin_lock(lock);
-                }
-            }
-          else if (spinlock->action == BOARDIOC_SPINLOCK_TRYLOCK)
-            {
-              if (flags != NULL)
-                {
-                  *flags = up_irq_save();
-                }
-
-              if (!spin_trylock(lock))
-                {
-                  ret = -EBUSY;
                   if (flags != NULL)
                     {
-                      up_irq_restore(*flags);
+                      *flags = spin_lock_irqsave(lock);
+                    }
+                  else
+                    {
+                      spin_lock(lock);
                     }
                 }
             }
+          else if (spinlock->action == BOARDIOC_SPINLOCK_TRYLOCK)
+            {
+              if (lock != NULL)
+              {
+                if (flags != NULL)
+                  {
+                    if (!spin_trylock_irqsave(lock, *flags))
+                      {
+                        ret = -EBUSY;
+                      }
+                  }
+                else if (!spin_trylock(lock))
+                  {
+                    ret = -EBUSY;
+                  }
+              }
+            }
           else if (spinlock->action == BOARDIOC_SPINLOCK_UNLOCK)
             {
-              if (flags != NULL)
-                {
-                  up_irq_restore(*flags);
-                }
-
               if (lock != NULL)
                 {
-                  spin_unlock(lock);
+                  if (flags != NULL)
+                    {
+                      spin_unlock_irqrestore(lock, *flags);
+                    }
+                  else
+                    {
+                      spin_unlock(lock);
+                    }
                 }
             }
           else

Reply via email to