[PATCH] lib: utils/serial: Clear LSR status and check RBR status

Neo neopimail at gmail.com
Mon Jun 16 02:41:08 PDT 2025


On some platforms, read RBR when it is empty may result in an error.

Signed-off-by: Yi Pei <neopimail at gmail.com>
---
lib/utils/serial/uart8250.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/utils/serial/uart8250.c b/lib/utils/serial/uart8250.c
index 82fb142a..ddae0aa3 100644
--- a/lib/utils/serial/uart8250.c
+++ b/lib/utils/serial/uart8250.c
@@ -134,9 +134,9 @@ int uart8250_init(unsigned long base, u32 in_freq,
u32 baudrate, u32 reg_shift,
/* 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);
+ if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR)
+ /* Read receive buffer */
+ get_reg(UART_RBR_OFFSET);
/* Set scratchpad */
set_reg(UART_SCR_OFFSET, 0x00);
-- 
2.34.1



More information about the opensbi mailing list