linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: greg@kroah.com, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org
Subject: [PATCH 12/12] tty: move the handling of the tty release logic
Date: Fri, 22 Jun 2012 16:47:58 +0100	[thread overview]
Message-ID: <20120622154645.1405.7749.stgit@localhost.localdomain> (raw)
In-Reply-To: <20120622153600.1405.15575.stgit@localhost.localdomain>

Now that we don't have tty->termios tied to drivers->tty we can untangle
the logic here. In addition we can push the removal logic out of the
destructor path.

At that point we can think about sorting out tty_port and console and all
the other ugly hangovers.

An important other property we now have is that the tty mutex does now cover
the drivers array. An assumption other bits of the code made and which is
necessary for the tty lock patch.

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

 drivers/tty/pty.c               |    8 --------
 drivers/tty/tty_io.c            |   16 +++++-----------
 drivers/tty/vt/vt.c             |    1 -
 drivers/usb/serial/usb-serial.c |    3 +--
 include/linux/tty.h             |    1 -
 include/linux/tty_driver.h      |   11 +++--------
 6 files changed, 9 insertions(+), 31 deletions(-)

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 56dcef4..f1ba793 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -497,12 +497,6 @@ static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
 	return tty;
 }
 
-static void pty_unix98_shutdown(struct tty_struct *tty)
-{
-	tty_driver_remove_tty(tty->driver, tty);
-	/* We have our own method as we don't use the tty index */
-}
-
 /* We have no need to install and remove our tty objects as devpts does all
    the work for us */
 
@@ -563,7 +557,6 @@ static const struct tty_operations ptm_unix98_ops = {
 	.unthrottle = pty_unthrottle,
 	.set_termios = pty_set_termios,
 	.ioctl = pty_unix98_ioctl,
-	.shutdown = pty_unix98_shutdown,
 	.resize = pty_resize
 };
 
@@ -579,7 +572,6 @@ static const struct tty_operations pty_unix98_ops = {
 	.chars_in_buffer = pty_chars_in_buffer,
 	.unthrottle = pty_unthrottle,
 	.set_termios = pty_set_termios,
-	.shutdown = pty_unix98_shutdown
 };
 
 /**
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 14db2a8..e062c1b 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1443,12 +1443,6 @@ void tty_free_termios(struct tty_struct *tty)
 }
 EXPORT_SYMBOL(tty_free_termios);
 
-void tty_shutdown(struct tty_struct *tty)
-{
-	tty_driver_remove_tty(tty->driver, tty);
-	tty_free_termios(tty);
-}
-EXPORT_SYMBOL(tty_shutdown);
 
 /**
  *	release_one_tty		-	release tty structure memory
@@ -1492,11 +1486,6 @@ static void queue_release_one_tty(struct kref *kref)
 {
 	struct tty_struct *tty = container_of(kref, struct tty_struct, kref);
 
-	if (tty->ops->shutdown)
-		tty->ops->shutdown(tty);
-	else
-		tty_shutdown(tty);
-
 	/* The hangup queue is now free so we can reuse it rather than
 	   waste a chunk of memory for each port */
 	INIT_WORK(&tty->hangup_work, release_one_tty);
@@ -1536,6 +1525,11 @@ static void release_tty(struct tty_struct *tty, int idx)
 	/* This should always be true but check for the moment */
 	WARN_ON(tty->index != idx);
 
+	if (tty->ops->shutdown)
+		tty->ops->shutdown(tty);
+	tty_free_termios(tty);
+	tty_driver_remove_tty(tty->driver, tty);
+
 	if (tty->link)
 		tty_kref_put(tty->link);
 	tty_kref_put(tty);
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 02c7cdd..2c9af9c 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -2839,7 +2839,6 @@ static void con_shutdown(struct tty_struct *tty)
 	console_lock();
 	vc->port.tty = NULL;
 	console_unlock();
-	tty_shutdown(tty);
 }
 
 static int default_italic_color    = 2; // green (ASCII)
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 003b191..3bca1ea 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -305,8 +305,7 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
  * Do the resource freeing and refcount dropping for the port.
  * Avoid freeing the console.
  *
- * Called asynchronously after the last tty kref is dropped,
- * and the tty layer has already done the tty_shutdown(tty);
+ * Called asynchronously after the last tty kref is dropped.
  */
 static void serial_cleanup(struct tty_struct *tty)
 {
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 86fce83..4132d9e 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -423,7 +423,6 @@ extern void tty_unthrottle(struct tty_struct *tty);
 extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
 extern void tty_driver_remove_tty(struct tty_driver *driver,
 				  struct tty_struct *tty);
-extern void tty_shutdown(struct tty_struct *tty);
 extern void tty_free_termios(struct tty_struct *tty);
 extern int is_current_pgrp_orphaned(void);
 extern struct pid *tty_get_pgrp(struct tty_struct *tty);
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 6e6dbb7..2bcf2a9 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -45,14 +45,9 @@
  *
  * void (*shutdown)(struct tty_struct * tty);
  *
- * 	This routine is called synchronously when a particular tty device
- *	is closed for the last time freeing up the resources.
- *	Note that tty_shutdown() is not called if ops->shutdown is defined.
- *	This means one is responsible to take care of calling ops->remove (e.g.
- *	via tty_driver_remove_tty) and releasing tty->termios.
- *	Note that this hook may be called from *all* the contexts where one
- *	uses tty refcounting (e.g. tty_port_tty_get).
- *
+ * 	This routine is called under the tty lock when a particular tty device
+ *	is closed for the last time. It executes before the tty resources
+ *	are freed so may execute while another function holds a tty kref.
  *
  * void (*cleanup)(struct tty_struct * tty);
  *


  parent reply	other threads:[~2012-06-22 15:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-22 15:36 [PATCH 01/12] f81232: correct stubbed termios handler Alan Cox
2012-06-22 15:38 ` [PATCH 02/12] usb: fix sillies in the metro USB driver Alan Cox
2012-06-24 21:49   ` Jiri Slaby
2012-07-23 16:32     ` Alan Cox
2012-06-22 15:40 ` [PATCH 03/12] tty: note race we need to fix Alan Cox
2012-06-22 15:42 ` [PATCH 04/12] gpio-sch: Fix resource leak Alan Cox
2012-06-27  2:25   ` Greg KH
2012-06-22 15:43 ` [PATCH 05/12] kobil_sct: Fix some bogus tty handling Alan Cox
2012-06-27  2:24   ` Greg KH
2012-06-22 15:43 ` [PATCH 06/12] 8250: use the 8250 register interface not the legacy one Alan Cox
2012-06-27  2:30   ` Greg KH
2012-06-22 15:44 ` [PATCH 07/12] 8250: propogate the bugs field Alan Cox
2012-06-22 15:44 ` [PATCH 08/12] 8250: add support for ASIX devices with a FIFO bug Alan Cox
2012-06-22 15:44 ` [PATCH 09/12] commit 22126843cb3c2a782c2d52614486115f3e9db478 Alan Cox
2012-06-22 15:36   ` Greg KH
2012-06-22 17:04     ` Alan Cox
2012-08-01  0:51       ` Yinghai Lu
2012-06-22 15:46 ` [PATCH 10/12] tty: tidy up the RESET_TERMIOS case Alan Cox
2012-06-22 15:46 ` [PATCH 11/12] vt: fix the keyboard/led locking Alan Cox
2012-06-22 15:47 ` Alan Cox [this message]
2012-08-01  0:47   ` [PATCH 12/12] tty: move the handling of the tty release logic Yinghai Lu
2012-06-27  2:22 ` [PATCH 01/12] f81232: correct stubbed termios handler Greg KH

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=20120622154645.1405.7749.stgit@localhost.localdomain \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@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;
as well as URLs for NNTP newsgroup(s).