Thread (9 messages) 9 messages, 4 authors, 2021-04-16

Re: [PATCH v2] serial: stm32: optimize spin lock usage

From: dillon min <hidden>
Date: 2021-04-12 14:04:50
Also in: linux-serial, lkml, oe-kbuild-all

Hi Johan,

Yes, there is no deadlock. my fault.
I forget the local_irq_save() plus spin_lock() is spin_lock_irqsave().

Thanks for your review. please ignore this patch.

Best regards

Dillon

On Mon, Apr 12, 2021 at 9:08 PM Johan Hovold [off-list ref] wrote:
On Mon, Apr 12, 2021 at 05:31:38PM +0800, dillon.minfei@gmail.com wrote:
quoted
From: dillon min <redacted>

To avoid potential deadlock in spin_lock usage, use spin_lock_irqsave,
spin_trylock_irqsave(), spin_unlock_irqrestore() in process context.
This doesn't make much sense as console_write can be called in any
context. And where's the deadlock you claim to be fixing here?
quoted
remove unused local_irq_save/restore call.

Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Gerald Baeza <redacted>
Cc: Erwan Le Ray <redacted>
Reported-by: kernel test robot <redacted>
Signed-off-by: dillon min <redacted>
---
v2: remove unused code from stm32_usart_threaded_interrupt() according from
    Greg's review.

 drivers/tty/serial/stm32-usart.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index b3675cf25a69..b1ba5e36e36e 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -1354,13 +1354,12 @@ static void stm32_usart_console_write(struct console *co, const char *s,
      u32 old_cr1, new_cr1;
      int locked = 1;

-     local_irq_save(flags);
      if (port->sysrq)
              locked = 0;
      else if (oops_in_progress)
-             locked = spin_trylock(&port->lock);
+             locked = spin_trylock_irqsave(&port->lock, flags);
      else
-             spin_lock(&port->lock);
+             spin_lock_irqsave(&port->lock, flags);

      /* Save and disable interrupts, enable the transmitter */
      old_cr1 = readl_relaxed(port->membase + ofs->cr1);
@@ -1374,8 +1373,7 @@ static void stm32_usart_console_write(struct console *co, const char *s,
      writel_relaxed(old_cr1, port->membase + ofs->cr1);

      if (locked)
-             spin_unlock(&port->lock);
-     local_irq_restore(flags);
+             spin_unlock_irqrestore(&port->lock, flags);
 }

 static int stm32_usart_console_setup(struct console *co, char *options)
Johan
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help