]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
serial: cortina: check RX FIFO status before reading data
authorNaveen Kumar Chaudhary <naveen.osdev@gmail.com>
Sun, 7 Jun 2026 15:33:43 +0000 (21:03 +0530)
committerTom Rini <trini@konsulko.com>
Tue, 23 Jun 2026 18:37:02 +0000 (12:37 -0600)
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@gmail.com>
drivers/serial/serial_cortina.c

index 3ae8fb465848362b69378aeba6109d411d5daa6b..de8af5b0574534fd16717aa6e179c3386fab5532 100644 (file)
@@ -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)