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 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2023-05-12 12:37:21 +08:00 committed by Xiang Xiao
parent 555506a584
commit 6da335cd81
1 changed files with 8 additions and 3 deletions

View File

@ -1340,9 +1340,13 @@ void u16550_serialinit(void)
int up_putc(int ch) int up_putc(int ch)
{ {
FAR struct u16550_s *priv = (FAR struct u16550_s *)CONSOLE_DEV.priv; 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 */ /* Check for LF */
@ -1354,7 +1358,8 @@ int up_putc(int ch)
} }
u16550_putc(priv, ch); u16550_putc(priv, ch);
u16550_restoreuartint(priv, ier); leave_critical_section(flags);
return ch; return ch;
} }
#endif #endif