[PATCH] tty: serial: manage irq with spin_lock_irqsave in SiFive console

Andy Chiu andy.chiu at sifive.com
Wed Jan 31 22:59:32 PST 2024


It is not safe to call spin_lock() with irq disabled on RT-linux.
Instead, transfer the code segment to spin_lock_irqsave to make it work
on both RT and non-RT linux.

Signed-off-by: Andy Chiu <andy.chiu at sifive.com>
---
 drivers/tty/serial/sifive.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/sifive.c b/drivers/tty/serial/sifive.c
index fa4c9336924f..3f0ddf8bfa7b 100644
--- a/drivers/tty/serial/sifive.c
+++ b/drivers/tty/serial/sifive.c
@@ -788,13 +788,12 @@ static void sifive_serial_console_write(struct console *co, const char *s,
 	if (!ssp)
 		return;
 
-	local_irq_save(flags);
 	if (ssp->port.sysrq)
 		locked = 0;
 	else if (oops_in_progress)
-		locked = spin_trylock(&ssp->port.lock);
+		locked = spin_trylock_irqsave(&ssp->port.lock, flags);
 	else
-		spin_lock(&ssp->port.lock);
+		spin_lock_irqsave(&ssp->port.lock, flags);
 
 	ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS);
 	__ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp);
@@ -804,8 +803,7 @@ static void sifive_serial_console_write(struct console *co, const char *s,
 	__ssp_writel(ier, SIFIVE_SERIAL_IE_OFFS, ssp);
 
 	if (locked)
-		spin_unlock(&ssp->port.lock);
-	local_irq_restore(flags);
+		spin_unlock_irqrestore(&ssp->port.lock, flags);
 }
 
 static int __init sifive_serial_console_setup(struct console *co, char *options)
-- 
2.17.1




More information about the linux-riscv mailing list