From 6da335cd819d5a5a37a98041e3530aa4035142ea Mon Sep 17 00:00:00 2001 From: hujun5 Date: Fri, 12 May 2023 12:37:21 +0800 Subject: [PATCH] driver/uart_16550: serial output can cause deadlock All interrupts must be disabled to prevent re-entrancy and to prevent interrupts from firing in the serial driver code. Signed-off-by: hujun5 --- drivers/serial/uart_16550.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/serial/uart_16550.c b/drivers/serial/uart_16550.c index f036a6ce16..fe84dc2a5f 100644 --- a/drivers/serial/uart_16550.c +++ b/drivers/serial/uart_16550.c @@ -1340,9 +1340,13 @@ void u16550_serialinit(void) int up_putc(int ch) { FAR struct u16550_s *priv = (FAR struct u16550_s *)CONSOLE_DEV.priv; - uart_datawidth_t ier; + irqstate_t flags; - u16550_disableuartint(priv, &ier); + /* All interrupts must be disabled to prevent re-entrancy and to prevent + * interrupts from firing in the serial driver code. + */ + + flags = enter_critical_section(); /* Check for LF */ @@ -1354,7 +1358,8 @@ int up_putc(int ch) } u16550_putc(priv, ch); - u16550_restoreuartint(priv, ier); + leave_critical_section(flags); + return ch; } #endif