public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@linux.intel.com>
To: greg@kroah.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: [PATCH 3/5] usb_serial: Use the shutdown() operation
Date: Tue, 06 Oct 2009 16:06:36 +0100	[thread overview]
Message-ID: <20091006150626.9431.34542.stgit@localhost.localdomain> (raw)
In-Reply-To: <20091006145413.9431.47083.stgit@localhost.localdomain>

As Alan Stern pointed out - now we have tty_port_open the shutdown method
and locking allow us to whack the other bits into the full helper methods
and provide a shutdown op which the tty port code will synchronize with 
setup for us.

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

 drivers/usb/serial/usb-serial.c |   39 +++++++++++----------------------------
 1 files changed, 11 insertions(+), 28 deletions(-)


diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 95c34da..e189338 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -253,15 +253,12 @@ static int serial_activate(struct tty_port *tport, struct tty_struct *tty)
 	struct usb_serial *serial = port->serial;
 	int retval;
 
-	if (mutex_lock_interruptible(&port->mutex))
-		return -ERESTARTSYS;
 	mutex_lock(&serial->disc_mutex);
 	if (serial->disconnected)
 		retval = -ENODEV;
 	else
 		retval = port->serial->type->open(tty, port);
 	mutex_unlock(&serial->disc_mutex);
-	mutex_unlock(&port->mutex);
 	return retval;
 }
 
@@ -275,57 +272,40 @@ static int serial_open(struct tty_struct *tty, struct file *filp)
 
 /**
  * serial_down - shut down hardware
- * @port: port to shut down
+ * @tport: tty port to shut down
  *
  * Shut down a USB serial port unless it is the console.  We never
- * shut down the console hardware as it will always be in use.
+ * shut down the console hardware as it will always be in use. Serialized
+ * against activate by the tport mutex and kept to matching open/close pairs
+ * of calls by the ASYNCB_INITIALIZED flag.
  */
-static void serial_down(struct usb_serial_port *port)
+static void serial_down(struct tty_port *tport)
 {
+	struct usb_serial_port *port =
+		container_of(tport, struct usb_serial_port, port);
 	struct usb_serial_driver *drv = port->serial->type;
-
 	/*
 	 * The console is magical.  Do not hang up the console hardware
 	 * or there will be tears.
 	 */
 	if (port->console)
 		return;
-
-	/* Don't call the close method if the hardware hasn't been
-	 * initialized.
-	 */
-	if (!test_and_clear_bit(ASYNCB_INITIALIZED, &port->port.flags))
-		return;
-
-	mutex_lock(&port->mutex);
 	if (drv->close)
 		drv->close(port);
-	mutex_unlock(&port->mutex);
 }
 
 static void serial_hangup(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
-
 	dbg("%s - port %d", __func__, port->number);
-
-	serial_down(port);
 	tty_port_hangup(&port->port);
 }
 
 static void serial_close(struct tty_struct *tty, struct file *filp)
 {
 	struct usb_serial_port *port = tty->driver_data;
-
 	dbg("%s - port %d", __func__, port->number);
-
-	if (tty_hung_up_p(filp))
-		return;
-	if (tty_port_close_start(&port->port, tty, filp) == 0)
-		return;
-	serial_down(port);
-	tty_port_close_end(&port->port, tty);
-	tty_port_tty_set(&port->port, NULL);
+	tty_port_close(&port->port, tty, filp);
 }
 
 /**
@@ -715,6 +695,7 @@ static const struct tty_port_operations serial_port_ops = {
 	.carrier_raised = serial_carrier_raised,
 	.dtr_rts = serial_dtr_rts,
 	.activate = serial_activate,
+	.shutdown = serial_down,
 };
 
 int usb_serial_probe(struct usb_interface *interface,
@@ -913,6 +894,8 @@ int usb_serial_probe(struct usb_interface *interface,
 		port->port.ops = &serial_port_ops;
 		port->serial = serial;
 		spin_lock_init(&port->lock);
+		/* Keep this for private driver use for the moment but
+		   should probably go away */
 		mutex_init(&port->mutex);
 		INIT_WORK(&port->work, usb_serial_port_work);
 		serial->port[i] = port;


  parent reply	other threads:[~2009-10-06 15:17 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-06 15:05 [PATCH 0/5] tty_port_open Alan Cox
2009-10-06 15:06 ` [PATCH 1/5] tty_port: add "tty_port_open" helper Alan Cox
2009-10-06 15:06 ` [PATCH 2/5] tty_port: coding style cleaning pass Alan Cox
2009-10-06 15:06 ` Alan Cox [this message]
2009-10-06 15:06 ` [PATCH 4/5] usb_serial: Kill port mutex Alan Cox
2009-10-07  5:02   ` Oliver Neukum
2009-10-07 16:03     ` Alan Stern
2009-10-07 16:10       ` Oliver Neukum
2009-10-07 16:34         ` Alan Stern
2009-10-07 16:46       ` Alan Cox
2009-10-07 17:23         ` Alan Stern
2009-10-07 18:25           ` Alan Cox
2009-10-07 18:52             ` Alan Stern
2009-10-07 20:56               ` Oliver Neukum
2009-10-07 21:02                 ` Alan Cox
2009-10-07 21:34                   ` Alan Stern
2009-10-08 13:43                     ` Oliver Neukum
2009-10-08 14:58                       ` Alan Stern
2009-10-08 15:27                         ` Oliver Neukum
2009-10-08 16:58                           ` Alan Stern
2009-10-08 20:06                             ` Alan Stern
2009-10-08 20:40                               ` Oliver Neukum
2009-10-08 21:19                                 ` Alan Cox
2009-10-08 21:31                                 ` Alan Stern
2009-10-08 22:31                                   ` Alan Cox
2009-10-08 11:37           ` Oliver Neukum
2009-10-06 15:06 ` [PATCH 5/5] opticon: Fix resume logic Alan Cox
2009-10-06 21:12   ` Oliver Neukum
2009-10-06 22:23     ` Alan Cox
2009-10-07 15:56       ` Johan Hovold
2009-10-07 16:01         ` Oliver Neukum
2009-10-07 15:56       ` Alan Stern

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=20091006150626.9431.34542.stgit@localhost.localdomain \
    --to=alan@linux.intel.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@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