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 aa2b0beb2c7dde5a97bff05f5c47b1a9b1b810fe
Author: jiangbo11 <[email protected]>
AuthorDate: Wed Jul 9 11:25:31 2025 +0800

    gpio: Logic dead code ,control flow issue
    
    Move the pid/flags/i/j locals of gpio_ioctl() into the blocks that use
    them, and only build the signal slot compaction in GPIOC_UNREGISTER
    when CONFIG_DEV_GPIO_NSIGNALS > 1, to fix the dead code and control
    flow issues reported by static analysis.
    
    Signed-off-by: jiangbo11 <[email protected]>
---
 drivers/ioexpander/gpio.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/drivers/ioexpander/gpio.c b/drivers/ioexpander/gpio.c
index 2e2a40a7f8e..b1af1eb02cd 100644
--- a/drivers/ioexpander/gpio.c
+++ b/drivers/ioexpander/gpio.c
@@ -748,13 +748,7 @@ static int gpio_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 {
   FAR struct inode *inode;
   FAR struct gpio_dev_s *dev;
-  irqstate_t flags;
   int ret = OK;
-#if CONFIG_DEV_GPIO_NSIGNALS > 0
-  pid_t pid;
-  int i;
-  int j;
-#endif
 
   inode = filep->f_inode;
   DEBUGASSERT(inode->i_private != NULL);
@@ -833,6 +827,10 @@ static int gpio_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 #if CONFIG_DEV_GPIO_NSIGNALS > 0
             if (arg)
               {
+                pid_t pid;
+                irqstate_t flags;
+                int i;
+
                 ret = nxsig_event_valid((FAR struct sigevent *)arg);
                 if (ret < 0)
                   {
@@ -896,15 +894,19 @@ static int gpio_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
         if (dev->gp_pintype >= GPIO_INTERRUPT_PIN)
           {
 #if CONFIG_DEV_GPIO_NSIGNALS > 0
-            pid = nxsched_getpid();
-            flags = spin_lock_irqsave(&dev->lock);
+            pid_t pid = nxsched_getpid();
+            irqstate_t flags = spin_lock_irqsave(&dev->lock);
+            int i;
+
             for (i = 0; i < CONFIG_DEV_GPIO_NSIGNALS; i++)
               {
                 if (pid == dev->gp_signals[i].gp_pid)
                   {
-#  ifdef CONFIG_SIG_EVTHREAD
+#   if CONFIG_DEV_GPIO_NSIGNALS > 1
+#     ifdef CONFIG_SIG_EVTHREAD
                     FAR struct sigwork_s *work;
-#  endif
+#     endif
+                    int j;
 
                     for (j = i + 1; j < CONFIG_DEV_GPIO_NSIGNALS; j++)
                       {
@@ -921,13 +923,14 @@ static int gpio_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
                       }
 
                     dev->gp_signals[j].gp_pid = 0;
-#  ifdef CONFIG_SIG_EVTHREAD
+#     ifdef CONFIG_SIG_EVTHREAD
                     work = &dev->gp_signals[j].gp_work;
                     spin_unlock_irqrestore(&dev->lock, flags);
                     nxsig_cancel_notification(work);
                     flags = spin_lock_irqsave(&dev->lock);
-#  endif
+#     endif
                     break;
+#  endif
                   }
               }
 

Reply via email to