From b8f370aa3714ef37023e523c37c1981b0a5d1e12 Mon Sep 17 00:00:00 2001 From: Yi Pei Date: Sun, 20 Jul 2025 20:37:18 +0530 Subject: [PATCH] lib: utils/serial: Clear LSR status and check RBR status On some platforms, read RBR when it is empty may result in an error. Signed-off-by: Yi Pei Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/CAFPVDjQZ1gpf8-u--RBbAL1Y0FfDN2vZ3g=wBw+Bp-8ppuz3HA@mail.gmail.com Signed-off-by: Anup Patel --- lib/utils/serial/uart8250.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/utils/serial/uart8250.c b/lib/utils/serial/uart8250.c index 82fb142a..17374082 100644 --- a/lib/utils/serial/uart8250.c +++ b/lib/utils/serial/uart8250.c @@ -133,10 +133,9 @@ int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift, set_reg(UART_FCR_OFFSET, 0x01); /* No modem control DTR RTS */ set_reg(UART_MCR_OFFSET, 0x00); - /* Clear line status */ - get_reg(UART_LSR_OFFSET); - /* Read receive buffer */ - get_reg(UART_RBR_OFFSET); + /* Clear line status and read receive buffer */ + if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR) + get_reg(UART_RBR_OFFSET); /* Set scratchpad */ set_reg(UART_SCR_OFFSET, 0x00);