Skip to content

Commit e533e4c

Browse files
esbengregkh
authored andcommitted
serial: imx: Introduce timeout when waiting on transmitter empty
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 <[email protected]> Acked-by: Marc Kleine-Budde <[email protected]> Link: https://lore.kernel.org/r/919647898c337a46604edcabaf13d42d80c0915d.1712837613.git.esben@geanix.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent abcd863 commit e533e4c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/tty/serial/imx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/slab.h>
2828
#include <linux/of.h>
2929
#include <linux/io.h>
30+
#include <linux/iopoll.h>
3031
#include <linux/dma-mapping.h>
3132

3233
#include <asm/irq.h>
@@ -2002,7 +2003,7 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count)
20022003
struct imx_port *sport = imx_uart_ports[co->index];
20032004
struct imx_port_ucrs old_ucr;
20042005
unsigned long flags;
2005-
unsigned int ucr1;
2006+
unsigned int ucr1, usr2;
20062007
int locked = 1;
20072008

20082009
if (sport->port.sysrq)
@@ -2033,8 +2034,8 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count)
20332034
* Finally, wait for transmitter to become empty
20342035
* and restore UCR1/2/3
20352036
*/
2036-
while (!(imx_uart_readl(sport, USR2) & USR2_TXDC));
2037-
2037+
read_poll_timeout_atomic(imx_uart_readl, usr2, usr2 & USR2_TXDC,
2038+
0, USEC_PER_SEC, false, sport, USR2);
20382039
imx_uart_ucrs_restore(sport, &old_ucr);
20392040

20402041
if (locked)

0 commit comments

Comments
 (0)