All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] mfd: ezx-pcap: Replace mutex_lock with spin_lock
@ 2022-10-26 12:20 Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2022-10-26 12:20 UTC (permalink / raw)
  To: huangfq.daxian; +Cc: linux-spi

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [bug report] mfd: ezx-pcap: Replace mutex_lock with spin_lock
@ 2023-07-31 14:11 Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2023-07-31 14:11 UTC (permalink / raw)
  To: huangfq.daxian; +Cc: kernel-janitors, Lee Jones

Hello Fuqian Huang,

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

drivers/mfd/ezx-pcap.c:102 ezx_pcap_read() warn: sleeping in atomic context
drivers/mfd/ezx-pcap.c:102 ezx_pcap_read() warn: sleeping in IRQ context

drivers/mfd/ezx-pcap.c
    93 int ezx_pcap_read(struct pcap_chip *pcap, u8 reg_num, u32 *value)
    94 {
    95         unsigned long flags;
    96         int ret;
    97 
    98         spin_lock_irqsave(&pcap->io_lock, flags);
               ^^^^^^^^^^^^^^^^^^
Taking a spinlock.

    99         *value = PCAP_REGISTER_READ_OP_BIT
    100                 | (reg_num << PCAP_REGISTER_ADDRESS_SHIFT);
    101 
--> 102         ret = ezx_pcap_putget(pcap, value);

My static checker agrees with you that this is an IRQ function but the
ezx_pcap_putget() function takes a mutex and we can't do that from an
IRQ function.

    103         spin_unlock_irqrestore(&pcap->io_lock, flags);
    104 
    105         return ret;
    106 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-31 14:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26 12:20 [bug report] mfd: ezx-pcap: Replace mutex_lock with spin_lock Dan Carpenter
2023-07-31 14:11 Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.