Skip to contentSkip to conversation

mfd: ezx-pcap: Replace mutex_lock with spin_lock

bug report Dan Carpenter 1 participant 1 message Oct 26, 2022 SPI

lore
Share & tools
lore
#0 lore raw

Hello Fuqian Huang,

The patch b65dc4f6b339: "mfd: ezx-pcap: Replace mutex_lock with spin_lock" from Aug 13, 2019, leads to the following Smatch static checker warning:

	drivers/spi/spi.c:1666 __spi_pump_transfer_message()
	warn: sleeping in atomic context

One problematic call tree is:

ezx_pcap_set_bits() <- disables preempt
-> ezx_pcap_putget()

     -> spi_sync()

drivers/mfd/ezx-pcap.c
109 int ezx_pcap_set_bits(struct pcap_chip *pcap, u8 reg_num, u32 mask, u32 val) 110 {

   111          unsigned long flags;
   112          int ret;
   113          u32 tmp = PCAP_REGISTER_READ_OP_BIT |

114 (reg_num << PCAP_REGISTER_ADDRESS_SHIFT);
115
116 spin_lock_irqsave(&pcap->io_lock, flags);

This use to be a mutex but it was change to a spinlock to avoid a sleeping in atomic bug.

   117          ret = ezx_pcap_putget(pcap, &tmp);

But ezx_pcap_putget() calls spi_sync() which takes a mutex so the fix is not complete.

   118          if (ret)
   119                  goto out_unlock;
   120  
   121          tmp &= (PCAP_REGISTER_VALUE_MASK & ~mask);
   122          tmp |= (val & mask) | PCAP_REGISTER_WRITE_OP_BIT |
   123                  (reg_num << PCAP_REGISTER_ADDRESS_SHIFT);
   124  
   125          ret = ezx_pcap_putget(pcap, &tmp);
   126  out_unlock:
   127          spin_unlock_irqrestore(&pcap->io_lock, flags);
   128  
   129          return ret;
   130  }

regards,
dan carpenter