[PATCH] serial: cortina: check RX FIFO status before reading data
Naveen Kumar Chaudhary
naveen.osdev at gmail.com
Sun Jun 7 17:33:43 CEST 2026
ca_serial_getc() reads from the URX_DATA register unconditionally
without first checking whether the RX FIFO contains valid data. When
the FIFO is empty, this returns whatever stale value is in the
register, which the DM serial framework interprets as a valid
character.
The DM serial framework expects getc() to return -EAGAIN when no data
is available, so it can handle retries and call schedule() to service
the watchdog between attempts.
Add a check of the UINFO register's UINFO_RX_FIFO_EMPTY bit before
reading URX_DATA, returning -EAGAIN when no data is pending. This
is consistent with how ca_serial_putc() already checks
UINFO_TX_FIFO_FULL before writing.
Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev at gmail.com>
---
drivers/serial/serial_cortina.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/serial/serial_cortina.c b/drivers/serial/serial_cortina.c
index 3ae8fb46584..de8af5b0574 100644
--- a/drivers/serial/serial_cortina.c
+++ b/drivers/serial/serial_cortina.c
@@ -83,11 +83,13 @@ int ca_serial_setbrg(struct udevice *dev, int baudrate)
static int ca_serial_getc(struct udevice *dev)
{
struct ca_uart_priv *priv = dev_get_priv(dev);
- int ch;
+ unsigned int status;
- ch = readl(priv->base + URX_DATA) & 0xFF;
+ status = readl(priv->base + UINFO);
+ if (status & UINFO_RX_FIFO_EMPTY)
+ return -EAGAIN;
- return (int)ch;
+ return readl(priv->base + URX_DATA) & 0xFF;
}
static int ca_serial_putc(struct udevice *dev, const char ch)
--
2.43.0
More information about the U-Boot
mailing list