linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] atmel_serial: Fix hang in set_termios when crtscts is enabled
@ 2009-06-08  8:15 Haavard Skinnemoen
  2009-06-08  8:24 ` Eirik Aanonsen
  0 siblings, 1 reply; 3+ messages in thread
From: Haavard Skinnemoen @ 2009-06-08  8:15 UTC (permalink / raw)
  To: Eirik Aanonsen
  Cc: kernel, linux-kernel, Nicolas Ferre, Andrew Victor, Alan Cox,
	Haavard Skinnemoen

After enabling hardware flow control, any subsequent termios call may
hang waiting for the transmitter to drain. This appears to be caused by
a busy-loop in set_termios() waiting for the transmitter to become
empty, which may take a very long time (or hang indefinitely) if the
device at the other end is blocking us.

A quick look through the tty and serial_core code indicates that any
necessary flushing (which is optional) has already been done at this
point, so there's no need for the driver to flush the transmitter on its
own.

Fix it by removing the busy-loop altogether.

Reported-by: Eirik Aanonsen <eaa@wprmedical.com>
Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
---
I have not tested this patch yet. Eirik, can you give it a try?

 drivers/serial/atmel_serial.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index b3497d7..338b15c 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -1104,11 +1104,13 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
 	/* update the per-port timeout */
 	uart_update_timeout(port, termios->c_cflag, baud);
 
-	/* save/disable interrupts and drain transmitter */
+	/*
+	 * save/disable interrupts. The tty layer will ensure that the
+	 * transmitter is empty if requested by the caller, so there's
+	 * no need to wait for it here.
+	 */
 	imr = UART_GET_IMR(port);
 	UART_PUT_IDR(port, -1);
-	while (!(UART_GET_CSR(port) & ATMEL_US_TXEMPTY))
-		cpu_relax();
 
 	/* disable receiver and transmitter */
 	UART_PUT_CR(port, ATMEL_US_TXDIS | ATMEL_US_RXDIS);
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] atmel_serial: Fix hang in set_termios when crtscts is enabled
  2009-06-08  8:15 [PATCH] atmel_serial: Fix hang in set_termios when crtscts is enabled Haavard Skinnemoen
@ 2009-06-08  8:24 ` Eirik Aanonsen
  2009-06-08  8:39   ` Haavard Skinnemoen
  0 siblings, 1 reply; 3+ messages in thread
From: Eirik Aanonsen @ 2009-06-08  8:24 UTC (permalink / raw)
  To: Haavard Skinnemoen
  Cc: kernel, linux-kernel, Nicolas Ferre, Andrew Victor, Alan Cox

> 
> Fix it by removing the busy-loop altogether.
> 
> Reported-by: Eirik Aanonsen <eaa@wprmedical.com>
> Signed-off-by: Haavard Skinnemoen <haavard.skinnemoen@atmel.com>
> ---
> I have not tested this patch yet. Eirik, can you give it a try?
> 
>  drivers/serial/atmel_serial.c |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/serial/atmel_serial.c
> b/drivers/serial/atmel_serial.c
> index b3497d7..338b15c 100644
> --- a/drivers/serial/atmel_serial.c
> +++ b/drivers/serial/atmel_serial.c
> @@ -1104,11 +1104,13 @@ static void atmel_set_termios(struct uart_port
> *port, struct ktermios *termios,
>  	/* update the per-port timeout */
>  	uart_update_timeout(port, termios->c_cflag, baud);
> 
> -	/* save/disable interrupts and drain transmitter */
> +	/*
> +	 * save/disable interrupts. The tty layer will ensure that the
> +	 * transmitter is empty if requested by the caller, so there's
> +	 * no need to wait for it here.
> +	 */
>  	imr = UART_GET_IMR(port);
>  	UART_PUT_IDR(port, -1);
> -	while (!(UART_GET_CSR(port) & ATMEL_US_TXEMPTY))
> -		cpu_relax();
> 
>  	/* disable receiver and transmitter */
>  	UART_PUT_CR(port, ATMEL_US_TXDIS | ATMEL_US_RXDIS);
> --
> 1.6.0.4

Works like a charm :) Thanx. I sis not use the patch but I just 
Added a 0& inside the condition to the while loop.


Regards
____________________________________________________
 
Eirik Aanonsen
SW Developer
E-mail: eaa@wprmedical.com 
Phone: +47 90 68 11 92
Fax: +47 37 03 56 77
____________________________________________________




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] atmel_serial: Fix hang in set_termios when crtscts is enabled
  2009-06-08  8:24 ` Eirik Aanonsen
@ 2009-06-08  8:39   ` Haavard Skinnemoen
  0 siblings, 0 replies; 3+ messages in thread
From: Haavard Skinnemoen @ 2009-06-08  8:39 UTC (permalink / raw)
  To: Eirik Aanonsen
  Cc: Nicolas Ferre, Andrew Victor, kernel, linux-kernel, Alan Cox

Eirik Aanonsen wrote:
> Works like a charm :) Thanx. I sis not use the patch but I just 
> Added a 0& inside the condition to the while loop.

Thanks for testing. I did a quick test on my NGW as well (using a UART
which isn't actually hooked up to anything) and I couldn't get it to
hang with the patch applied.

Haavard

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-06-08  8:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-08  8:15 [PATCH] atmel_serial: Fix hang in set_termios when crtscts is enabled Haavard Skinnemoen
2009-06-08  8:24 ` Eirik Aanonsen
2009-06-08  8:39   ` Haavard Skinnemoen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).