linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] serial_core: fix uart PORT_UNKNOWN handling
@ 2014-04-23 10:33 Thomas Pfaff
  2014-04-23 12:34 ` One Thousand Gnomes
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Pfaff @ 2014-04-23 10:33 UTC (permalink / raw)
  To: gregkh, jslaby, gnomes; +Cc: linux-kernel

From: "Thomas Pfaff" <tpfaff@pcs.com>

While porting a RS485 driver from 2.6.29 to 3.14, i noticed that the serial tty 
driver could break it by using uart ports that it does not own :

1. uart_change_pm ist called during uart_open and calls the uart pm function
   without checking for PORT_UNKNOWN.
   The fix is to move uart_change_pm from uart_open to uart_port_startup.
2. The return code from the uart request_port call in uart_set_info is not
   handled properly, leading to the situation that the serial driver also
   thinks it owns the uart ports.
   This can triggered by doing following actions :

   setserial /dev/ttyS0 uart none    # release the uart ports
   modprobe lirc-serial              # or any other device that uses the uart
   setserial /dev/ttyS0 uart 16550   # gives no error and the uart tty driver
                                     # can use the ports as well

Signed-off-by: Thomas Pfaff <tpfaff@pcs.com>
---
diff -urp linux-3.14.org/drivers/tty/serial/serial_core.c linux-3.14/drivers/tty/serial/serial_core.c
--- linux-3.14.org/drivers/tty/serial/serial_core.c	2014-03-31 05:40:15.000000000 +0200
+++ linux-3.14/drivers/tty/serial/serial_core.c	2014-04-09 16:41:03.940046814 +0200
@@ -138,6 +138,11 @@ static int uart_port_startup(struct tty_
 		return 1;
 
 	/*
+	 * Make sure the device is in D0 state.
+	 */
+	uart_change_pm(state, UART_PM_STATE_ON);
+
+	/*
 	 * Initialise and allocate the transmit and temporary
 	 * buffer.
 	 */
@@ -826,25 +831,29 @@ static int uart_set_info(struct tty_stru
 		 * If we fail to request resources for the
 		 * new port, try to restore the old settings.
 		 */
-		if (retval && old_type != PORT_UNKNOWN) {
+		if (retval) {
 			uport->iobase = old_iobase;
 			uport->type = old_type;
 			uport->hub6 = old_hub6;
 			uport->iotype = old_iotype;
 			uport->regshift = old_shift;
 			uport->mapbase = old_mapbase;
-			retval = uport->ops->request_port(uport);
-			/*
-			 * If we failed to restore the old settings,
-			 * we fail like this.
-			 */
-			if (retval)
-				uport->type = PORT_UNKNOWN;
 
-			/*
-			 * We failed anyway.
-			 */
-			retval = -EBUSY;
+			if (old_type != PORT_UNKNOWN) {
+				retval = uport->ops->request_port(uport);
+				/*
+				 * If we failed to restore the old settings,
+				 * we fail like this.
+				 */
+				if (retval)
+					uport->type = PORT_UNKNOWN;
+
+				/*
+				 * We failed anyway.
+				 */
+				retval = -EBUSY;
+			}
+
 			/* Added to return the correct error -Ram Gupta */
 			goto exit;
 		}
@@ -1570,12 +1579,6 @@ static int uart_open(struct tty_struct *
 	}
 
 	/*
-	 * Make sure the device is in D0 state.
-	 */
-	if (port->count == 1)
-		uart_change_pm(state, UART_PM_STATE_ON);
-
-	/*
 	 * Start up the serial port.
 	 */
 	retval = uart_startup(tty, state, 0);

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

* Re: [PATCH v2] serial_core: fix uart PORT_UNKNOWN handling
  2014-04-23 10:33 [PATCH v2] serial_core: fix uart PORT_UNKNOWN handling Thomas Pfaff
@ 2014-04-23 12:34 ` One Thousand Gnomes
  0 siblings, 0 replies; 2+ messages in thread
From: One Thousand Gnomes @ 2014-04-23 12:34 UTC (permalink / raw)
  To: Thomas Pfaff; +Cc: gregkh, jslaby, linux-kernel

On Wed, 23 Apr 2014 12:33:22 +0200
Thomas Pfaff <tpfaff@pcs.com> wrote:

> From: "Thomas Pfaff" <tpfaff@pcs.com>
> 
> While porting a RS485 driver from 2.6.29 to 3.14, i noticed that the serial tty 
> driver could break it by using uart ports that it does not own :
> 
> 1. uart_change_pm ist called during uart_open and calls the uart pm function
>    without checking for PORT_UNKNOWN.
>    The fix is to move uart_change_pm from uart_open to uart_port_startup.
> 2. The return code from the uart request_port call in uart_set_info is not
>    handled properly, leading to the situation that the serial driver also
>    thinks it owns the uart ports.
>    This can triggered by doing following actions :
> 
>    setserial /dev/ttyS0 uart none    # release the uart ports
>    modprobe lirc-serial              # or any other device that uses the uart
>    setserial /dev/ttyS0 uart 16550   # gives no error and the uart tty driver
>                                      # can use the ports as well
> 
> Signed-off-by: Thomas Pfaff <tpfaff@pcs.com>
Reviewed-by: Alan Cox <alan@linux.intel.com>

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

end of thread, other threads:[~2014-04-23 12:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-23 10:33 [PATCH v2] serial_core: fix uart PORT_UNKNOWN handling Thomas Pfaff
2014-04-23 12:34 ` One Thousand Gnomes

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).