All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
To: <linux-serial@vger.kernel.org>
Cc: <michal.simek@xilinx.com>, <gregkh@linuxfoundation.org>,
	<shubhrajyoti.datta@gmail.com>, <git@amd.com>,
	Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Subject: [PATCH v2 6/7] tty: xilinx_uartps: Add timeout waiting for loop
Date: Fri, 29 Jul 2022 17:17:47 +0530	[thread overview]
Message-ID: <20220729114748.18332-7-shubhrajyoti.datta@xilinx.com> (raw)
In-Reply-To: <20220729114748.18332-1-shubhrajyoti.datta@xilinx.com>

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>
---
 drivers/tty/serial/xilinx_uartps.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index e119da69e190..a1ff03f24f51 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -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);
 }
 
-- 
2.25.1


  parent reply	other threads:[~2022-07-29 11:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-29 11:47 [PATCH v2 0/7] tty: xilinx_uartps: fixes and improvements Shubhrajyoti Datta
2022-07-29 11:47 ` [PATCH v2 1/7] tty: xilinx_uartps: Check clk_enable return value Shubhrajyoti Datta
2022-07-29 11:47 ` [PATCH v2 2/7] tty: xilinx_uartps: Update copyright text to correct format Shubhrajyoti Datta
2022-07-29 13:46   ` Greg KH
2022-08-02  7:29     ` Datta, Shubhrajyoti
2022-07-29 11:47 ` [PATCH v2 3/7] tty: xilinx_uartps: Initialise the read_status_mask Shubhrajyoti Datta
2022-07-29 11:47 ` [PATCH v2 4/7] tty: xilinx_uartps: Fix the ignore_status Shubhrajyoti Datta
2022-07-29 11:47 ` [PATCH v2 5/7] tty: xilinx_uartps: Prevent writes when the controller is disabled Shubhrajyoti Datta
2022-07-29 11:47 ` Shubhrajyoti Datta [this message]
2022-07-29 11:47 ` [PATCH v2 7/7] tty: xilinx_uartps: Check the clk_enable return value Shubhrajyoti Datta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220729114748.18332-7-shubhrajyoti.datta@xilinx.com \
    --to=shubhrajyoti.datta@xilinx.com \
    --cc=git@amd.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=shubhrajyoti.datta@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.