mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Pfaff <tpfaff@pcs.com>
To: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"jslaby@suse.cz" <jslaby@suse.cz>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH] serial_core: fix uart PORT_UNKNOWN handling
Date: Wed, 9 Apr 2014 13:22:14 +0200	[thread overview]
Message-ID: <alpine.LNX.2.00.1404091151430.6519@lxtpfaff.pcs.ditec.de> (raw)

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.
2. uart_shutdown is called from uart_set_info and does not check it either.
3. 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-08 16:51:28.176459065 +0200
@@ -225,6 +225,9 @@ static void uart_shutdown(struct tty_str
 	struct uart_port *uport = state->uart_port;
 	struct tty_port *port = &state->port;
 
+	if (uport->type == PORT_UNKNOWN)
+		return;
+
 	/*
 	 * Set the TTY IO error marker
 	 */
@@ -826,25 +829,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;
 		}
@@ -1900,6 +1907,9 @@ static void uart_change_pm(struct uart_s
 {
 	struct uart_port *port = state->uart_port;
 
+	if (port->type == PORT_UNKNOWN)
+		return;
+
 	if (state->pm_state != pm_state) {
 		if (port->ops->pm)
 			port->ops->pm(port, pm_state, state->pm_state);

             reply	other threads:[~2014-04-09 11:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-09 11:22 Thomas Pfaff [this message]
2014-04-09 12:39 ` One Thousand Gnomes
2014-04-09 15:06   ` Thomas Pfaff
2014-04-16 20:25     ` gregkh

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=alpine.LNX.2.00.1404091151430.6519@lxtpfaff.pcs.ditec.de \
    --to=tpfaff@pcs.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®