]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tty: xilinx_uartps: Add timeout waiting for loop
authorShubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Fri, 29 Jul 2022 11:47:47 +0000 (17:17 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 Aug 2022 11:26:01 +0000 (13:26 +0200)
There is a potential infinite loop while waiting for the
the TXFULL to deassert. Adds the error message and timeout to
avoid infinite loop if it fails to get the TX fifo not full.

Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Link: https://lore.kernel.org/r/20220729114748.18332-7-shubhrajyoti.datta@xilinx.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/xilinx_uartps.c

index d1aa44febaea7e5ebeb7d034f2ab68163f5b29d9..da83ae6df1e082ceb1e984184f5c1a42e86d294d 100644 (file)
@@ -1147,8 +1147,20 @@ static void cdns_uart_console_putchar(struct uart_port *port, unsigned char ch)
                }
                cpu_relax();
        }
-       while (readl(port->membase + CDNS_UART_SR) & CDNS_UART_SR_TXFULL)
+
+       timeout = jiffies + msecs_to_jiffies(1000);
+       while (1) {
+               ctrl_reg = readl(port->membase + CDNS_UART_SR);
+
+               if (!(ctrl_reg & CDNS_UART_SR_TXFULL))
+                       break;
+               if (time_after(jiffies, timeout)) {
+                       dev_warn(port->dev,
+                                "timeout waiting for TX fifo\n");
+                       return;
+               }
                cpu_relax();
+       }
        writel(ch, port->membase + CDNS_UART_FIFO);
 }