summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi Pei <[email protected]>2025-07-20 20:37:18 +0530
committerAnup Patel <[email protected]>2025-07-20 20:37:18 +0530
commitb8f370aa3714ef37023e523c37c1981b0a5d1e12 (patch)
tree4433d40b5f5c7e24c9a7c97f4472a83641a33c78
parenta32a91069119e7a5aa31e6bc51d5e00860be3d80 (diff)
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/CAFPVDjQZ1gpf8-u--RBbAL1Y0FfDN2vZ3g=wBw+Bp-8ppuz3HA@mail.gmail.com Signed-off-by: Anup Patel <[email protected]>
-rw-r--r--lib/utils/serial/uart8250.c7
1 files 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);