Skip to content

Commit cea37af

Browse files
jhovoldgregkh
authored andcommitted
serial: stm32: defer sysrq processing
Use the uart_unlock_and_check_sysrq() helper to defer sysrq processing until receive processing is done and the port lock has been released. This allows cleaning up the console_write() implementation by not having to work around the recursive sysrq case (by dropping locking completely) and also makes the console code work with PREEMPT_RT by no longer relying on local_irq_save(). Reviewed-by: Valentin Caron<valentin.caron@foss.st.com> Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://lore.kernel.org/r/20210416140557.25177-4-johan@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e359b44 commit cea37af

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

‎drivers/tty/serial/stm32-usart.c‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ static void stm32_usart_receive_chars(struct uart_port *port, bool threaded)
270270
}
271271
}
272272

273-
if (uart_handle_sysrq_char(port, c))
273+
if (uart_prepare_sysrq_char(port, c))
274274
continue;
275275
uart_insert_char(port, sr, USART_SR_ORE, c, flag);
276276
}
277277

278-
spin_unlock(&port->lock);
278+
uart_unlock_and_check_sysrq(port);
279279

280280
tty_flip_buffer_push(tport);
281281
}
@@ -1430,13 +1430,10 @@ static void stm32_usart_console_write(struct console *co, const char *s,
14301430
u32 old_cr1, new_cr1;
14311431
int locked = 1;
14321432

1433-
local_irq_save(flags);
1434-
if (port->sysrq)
1435-
locked = 0;
1436-
else if (oops_in_progress)
1437-
locked = spin_trylock(&port->lock);
1433+
if (oops_in_progress)
1434+
locked = spin_trylock_irqsave(&port->lock, flags);
14381435
else
1439-
spin_lock(&port->lock);
1436+
spin_lock_irqsave(&port->lock, flags);
14401437

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

14521449
if (locked)
1453-
spin_unlock(&port->lock);
1454-
local_irq_restore(flags);
1450+
spin_unlock_irqrestore(&port->lock, flags);
14551451
}
14561452

14571453
static int stm32_usart_console_setup(struct console *co, char *options)

0 commit comments

Comments
 (0)