public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Esben Haabendal <esben@geanix.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sasha Levin <sashal@kernel.org>,
	jirislaby@kernel.org, shawnguo@kernel.org,
	u.kleine-koenig@pengutronix.de, ilpo.jarvinen@linux.intel.com,
	l.sanfilippo@kunbus.com, cniedermaier@dh-electronics.com,
	martin.fuzzey@flowbird.group, robh@kernel.org,
	tglx@linutronix.de, rickaran@axis.com,
	linux-serial@vger.kernel.org, imx@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH AUTOSEL 6.8 12/24] serial: imx: Introduce timeout when waiting on transmitter empty
Date: Wed,  5 Jun 2024 07:50:22 -0400	[thread overview]
Message-ID: <20240605115101.2962372-12-sashal@kernel.org> (raw)
In-Reply-To: <20240605115101.2962372-1-sashal@kernel.org>

From: Esben Haabendal <esben@geanix.com>

[ Upstream commit e533e4c62e9993e62e947ae9bbec34e4c7ae81c2 ]

By waiting at most 1 second for USR2_TXDC to be set, we avoid a potential
deadlock.

In case of the timeout, there is not much we can do, so we simply ignore
the transmitter state and optimistically try to continue.

Signed-off-by: Esben Haabendal <esben@geanix.com>
Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://lore.kernel.org/r/919647898c337a46604edcabaf13d42d80c0915d.1712837613.git.esben@geanix.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/tty/serial/imx.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index e148132506161..09c1678ddfd49 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -26,6 +26,7 @@
 #include <linux/slab.h>
 #include <linux/of.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/dma-mapping.h>
 
 #include <asm/irq.h>
@@ -2010,7 +2011,7 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count)
 	struct imx_port *sport = imx_uart_ports[co->index];
 	struct imx_port_ucrs old_ucr;
 	unsigned long flags;
-	unsigned int ucr1;
+	unsigned int ucr1, usr2;
 	int locked = 1;
 
 	if (sport->port.sysrq)
@@ -2041,8 +2042,8 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count)
 	 *	Finally, wait for transmitter to become empty
 	 *	and restore UCR1/2/3
 	 */
-	while (!(imx_uart_readl(sport, USR2) & USR2_TXDC));
-
+	read_poll_timeout_atomic(imx_uart_readl, usr2, usr2 & USR2_TXDC,
+				 0, USEC_PER_SEC, false, sport, USR2);
 	imx_uart_ucrs_restore(sport, &old_ucr);
 
 	if (locked)
-- 
2.43.0


  parent reply	other threads:[~2024-06-05 11:51 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05 11:50 [PATCH AUTOSEL 6.8 01/24] usb: gadget: uvc: configfs: ensure guid to be valid before set Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 02/24] f2fs: remove clear SB_INLINECRYPT flag in default_options Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 03/24] usb: typec: ucsi_glink: rework quirks implementation Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 04/24] usb: misc: uss720: check for incompatible versions of the Belkin F5U002 Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 05/24] Avoid hw_desc array overrun in dw-axi-dmac Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 06/24] usb: dwc3: pci: Don't set "linux,phy_charger_detect" property on Lenovo Yoga Tab2 1380 Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 07/24] usb: typec: ucsi_glink: drop special handling for CCI_BUSY Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 08/24] udf: udftime: prevent overflow in udf_disk_stamp_to_time() Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 09/24] PCI/PM: Avoid D3cold for HP Pavilion 17 PC/1972 PCIe Ports Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 10/24] f2fs: don't set RO when shutting down f2fs Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 11/24] MIPS: Octeon: Add PCIe link status check Sasha Levin
2024-06-05 11:50 ` Sasha Levin [this message]
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 13/24] serial: exar: adding missing CTI and Exar PCI ids Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 14/24] usb: gadget: function: Remove usage of the deprecated ida_simple_xx() API Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 15/24] usb: dwc3: core: Access XHCI address space temporarily to read port info Sasha Levin
2024-06-05 11:54   ` Johan Hovold
2024-07-22 12:56     ` Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 16/24] f2fs: fix to do sanity check on i_xattr_nid in sanity_check_inode() Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 17/24] tty: add the option to have a tty reject a new ldisc Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 18/24] greybus: Fix use-after-free bug in gb_interface_release due to race condition Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 19/24] cxl: Add post-reset warning if reset results in loss of previously committed HDM decoders Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 20/24] vfio/pci: Collect hot-reset devices to local buffer Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 21/24] cpufreq: amd-pstate: fix memory leak on CPU EPP exit Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 22/24] ACPI: EC: Install address space handler at the namespace root Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 23/24] PCI: Do not wait for disconnected devices when resuming Sasha Levin
2024-06-05 11:50 ` [PATCH AUTOSEL 6.8 24/24] OPP: Fix required_opp_tables for multiple genpds using same table Sasha Levin

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=20240605115101.2962372-12-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=cniedermaier@dh-electronics.com \
    --cc=esben@geanix.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=imx@lists.linux.dev \
    --cc=jirislaby@kernel.org \
    --cc=l.sanfilippo@kunbus.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=martin.fuzzey@flowbird.group \
    --cc=mkl@pengutronix.de \
    --cc=rickaran@axis.com \
    --cc=robh@kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=u.kleine-koenig@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox