public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] uart_get_baud_rate: stop mangling termios
@ 2008-02-20 20:44 Alan Cox
  2008-03-04  7:13 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Cox @ 2008-02-20 20:44 UTC (permalink / raw)
  To: akpm, linux-kernel

Russell King noticed this one: We have to avoid replacing B0 when we pick
a baud rate for a "hung up" port. Ugly but the proper fix is in the tty
layer and means changing the tty<->serial interfaces so we will defer
that for now.

Signed-off-by: Alan Cox <alan@redhat.com>

diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-rc2-mm1/drivers/serial/serial_core.c linux-2.6.25-rc2-mm1/drivers/serial/serial_core.c
--- linux.vanilla-2.6.25-rc2-mm1/drivers/serial/serial_core.c	2008-02-19 11:03:01.000000000 +0000
+++ linux-2.6.25-rc2-mm1/drivers/serial/serial_core.c	2008-02-20 16:22:49.000000000 +0000
@@ -329,13 +329,15 @@
  *	If it's still invalid, we try 9600 baud.
  *
  *	Update the @termios structure to reflect the baud rate
- *	we're actually going to be using.
+ *	we're actually going to be using. Don't do this for the case
+ *	where B0 is requested ("hang up").
  */
 unsigned int
 uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
 		   struct ktermios *old, unsigned int min, unsigned int max)
 {
 	unsigned int try, baud, altbaud = 38400;
+	int hung_up;
 	upf_t flags = port->flags & UPF_SPD_MASK;
 
 	if (flags == UPF_SPD_HI)
@@ -360,8 +362,10 @@
 		/*
 		 * Special case: B0 rate.
 		 */
-		if (baud == 0)
+		if (baud == 0) {
+			hung_up = 1;
 			baud = 9600;
+		}
 
 		if (baud >= min && baud <= max)
 			return baud;
@@ -373,7 +377,9 @@
 		termios->c_cflag &= ~CBAUD;
 		if (old) {
 			baud = tty_termios_baud_rate(old);
-			tty_termios_encode_baud_rate(termios, baud, baud);
+			if (!hung_up)
+				tty_termios_encode_baud_rate(termios,
+								baud, baud);
 			old = NULL;
 			continue;
 		}
@@ -382,7 +388,8 @@
 		 * As a last resort, if the quotient is zero,
 		 * default to 9600 bps
 		 */
-		tty_termios_encode_baud_rate(termios, 9600, 9600);
+		if (!hung_up)
+			tty_termios_encode_baud_rate(termios, 9600, 9600);
 	}
 
 	return 0;

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

* Re: [PATCH] uart_get_baud_rate: stop mangling termios
  2008-02-20 20:44 [PATCH] uart_get_baud_rate: stop mangling termios Alan Cox
@ 2008-03-04  7:13 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2008-03-04  7:13 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel

On Wed, 20 Feb 2008 20:44:06 +0000 Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> Russell King noticed this one: We have to avoid replacing B0 when we pick
> a baud rate for a "hung up" port. Ugly but the proper fix is in the tty
> layer and means changing the tty<->serial interfaces so we will defer
> that for now.
> 
> Signed-off-by: Alan Cox <alan@redhat.com>
> 
> diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-rc2-mm1/drivers/serial/serial_core.c linux-2.6.25-rc2-mm1/drivers/serial/serial_core.c
> --- linux.vanilla-2.6.25-rc2-mm1/drivers/serial/serial_core.c	2008-02-19 11:03:01.000000000 +0000
> +++ linux-2.6.25-rc2-mm1/drivers/serial/serial_core.c	2008-02-20 16:22:49.000000000 +0000
> @@ -329,13 +329,15 @@
>   *	If it's still invalid, we try 9600 baud.
>   *
>   *	Update the @termios structure to reflect the baud rate
> - *	we're actually going to be using.
> + *	we're actually going to be using. Don't do this for the case
> + *	where B0 is requested ("hang up").
>   */
>  unsigned int
>  uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
>  		   struct ktermios *old, unsigned int min, unsigned int max)
>  {
>  	unsigned int try, baud, altbaud = 38400;
> +	int hung_up;
>  	upf_t flags = port->flags & UPF_SPD_MASK;
>  
>  	if (flags == UPF_SPD_HI)
> @@ -360,8 +362,10 @@
>  		/*
>  		 * Special case: B0 rate.
>  		 */
> -		if (baud == 0)
> +		if (baud == 0) {
> +			hung_up = 1;
>  			baud = 9600;
> +		}
>  
>  		if (baud >= min && baud <= max)
>  			return baud;
> @@ -373,7 +377,9 @@
>  		termios->c_cflag &= ~CBAUD;
>  		if (old) {
>  			baud = tty_termios_baud_rate(old);
> -			tty_termios_encode_baud_rate(termios, baud, baud);
> +			if (!hung_up)
> +				tty_termios_encode_baud_rate(termios,
> +								baud, baud);
>  			old = NULL;
>  			continue;
>  		}
> @@ -382,7 +388,8 @@
>  		 * As a last resort, if the quotient is zero,
>  		 * default to 9600 bps
>  		 */
> -		tty_termios_encode_baud_rate(termios, 9600, 9600);
> +		if (!hung_up)
> +			tty_termios_encode_baud_rate(termios, 9600, 9600);
>  	}
>  
>  	return 0;

drivers/serial/serial_core.c: In function 'uart_get_baud_rate':
drivers/serial/serial_core.c:340: warning: 'hung_up' may be used uninitialized in this function

It isn't completely obvious that this is a falsie.


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

end of thread, other threads:[~2008-03-04  7:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-20 20:44 [PATCH] uart_get_baud_rate: stop mangling termios Alan Cox
2008-03-04  7:13 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox