All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rob Herring <robh@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Marcel Holtmann <marcel@holtmann.org>,
	Jiri Slaby <jslaby@suse.com>, Sebastian Reichel <sre@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>,
	"Dr . H . Nikolaus Schaller" <hns@goldelico.com>,
	Peter Hurley <peter@hurleysoftware.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Alan Cox <gnomes@lxorguk.ukuu.org.uk>
Cc: Loic Poulain <loic.poulain@intel.com>,
	Pavel Machek <pavel@ucw.cz>, NeilBrown <neil@brown.name>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-bluetooth@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/9] tty: move the non-file related parts of tty_release to new tty_release_struct
Date: Mon, 16 Jan 2017 16:54:28 -0600	[thread overview]
Message-ID: <20170116225436.17505-2-robh@kernel.org> (raw)
In-Reply-To: <20170116225436.17505-1-robh@kernel.org>

For in-kernel tty users, we need to be able to create and destroy
'struct tty' that are not associated with a file. The creation side is
fine, but tty_release() needs to be split into the file handle portion
and the struct tty portion. Introduce a new function, tty_release_struct,
to handle just the destroying of a struct tty.

Signed-off-by: Rob Herring <robh@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-By: Sebastian Reichel <sre@kernel.org>
---
v2:
- Add kerneldoc for tty_release_struct

 drivers/tty/tty_io.c | 50 ++++++++++++++++++++++++++++++++------------------
 include/linux/tty.h  |  1 +
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 734a635e7363..4790c0fb5a45 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1745,6 +1745,37 @@ static int tty_release_checks(struct tty_struct *tty, int idx)
 }

 /**
+ *	tty_release_struct	-	release a tty struct
+ *	@tty: tty device
+ *	@idx: index of the tty
+ *
+ *	Performs the final steps to release and free a tty device. It is
+ *	roughly the reverse of tty_init_dev.
+ */
+void tty_release_struct(struct tty_struct *tty, int idx)
+{
+	/*
+	 * Ask the line discipline code to release its structures
+	 */
+	tty_ldisc_release(tty);
+
+	/* Wait for pending work before tty destruction commmences */
+	tty_flush_works(tty);
+
+	tty_debug_hangup(tty, "freeing structure\n");
+	/*
+	 * The release_tty function takes care of the details of clearing
+	 * the slots and preserving the termios structure. The tty_unlock_pair
+	 * should be safe as we keep a kref while the tty is locked (so the
+	 * unlock never unlocks a freed tty).
+	 */
+	mutex_lock(&tty_mutex);
+	release_tty(tty, idx);
+	mutex_unlock(&tty_mutex);
+}
+EXPORT_SYMBOL_GPL(tty_release_struct);
+
+/**
  *	tty_release		-	vfs callback for close
  *	@inode: inode of tty
  *	@filp: file pointer for handle to tty
@@ -1898,25 +1929,8 @@ int tty_release(struct inode *inode, struct file *filp)
 		return 0;

 	tty_debug_hangup(tty, "final close\n");
-	/*
-	 * Ask the line discipline code to release its structures
-	 */
-	tty_ldisc_release(tty);
-
-	/* Wait for pending work before tty destruction commmences */
-	tty_flush_works(tty);
-
-	tty_debug_hangup(tty, "freeing structure\n");
-	/*
-	 * The release_tty function takes care of the details of clearing
-	 * the slots and preserving the termios structure. The tty_unlock_pair
-	 * should be safe as we keep a kref while the tty is locked (so the
-	 * unlock never unlocks a freed tty).
-	 */
-	mutex_lock(&tty_mutex);
-	release_tty(tty, idx);
-	mutex_unlock(&tty_mutex);

+	tty_release_struct(tty, idx);
 	return 0;
 }

diff --git a/include/linux/tty.h b/include/linux/tty.h
index 40144f382516..86c7853282b7 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -528,6 +528,7 @@ extern int tty_alloc_file(struct file *file);
 extern void tty_add_file(struct tty_struct *tty, struct file *file);
 extern void tty_free_file(struct file *file);
 extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
+extern void tty_release_struct(struct tty_struct *tty, int idx);
 extern int tty_release(struct inode *inode, struct file *filp);
 extern void tty_init_termios(struct tty_struct *tty);
 extern int tty_standard_install(struct tty_driver *driver,
--
2.10.1

  reply	other threads:[~2017-01-16 22:56 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-16 22:54 [PATCH v2 0/9] Serial slave device bus Rob Herring
2017-01-16 22:54 ` Rob Herring [this message]
2017-01-16 22:54 ` [PATCH v2 2/9] tty_port: allow a port to be opened with a tty that has no file handle Rob Herring
2017-01-17 14:57   ` One Thousand Gnomes
2017-01-19 13:37   ` Greg Kroah-Hartman
2017-01-19 15:05     ` Rob Herring
2017-01-19 15:23       ` Rob Herring
2017-01-16 22:54 ` [PATCH v2 3/9] tty_port: make tty_port_register_device wrap tty_port_register_device_attr Rob Herring
2017-01-16 22:54 ` [PATCH v2 4/9] tty: constify tty_ldisc_receive_buf buffer pointer Rob Herring
2017-01-19 16:24   ` Greg Kroah-Hartman
2017-01-16 22:54 ` [PATCH v2 5/9] tty_port: Add port client functions Rob Herring
2017-01-16 22:54 ` [PATCH v2 6/9] dt/bindings: Add a serial/UART attached device binding Rob Herring
2017-01-16 22:54 ` [PATCH v2 7/9] serdev: Introduce new bus for serial attached devices Rob Herring
2017-01-18 11:53   ` Frédéric Danis
2017-01-18 21:26     ` Rob Herring
2017-01-18 21:26       ` Rob Herring
2017-01-18 21:26       ` Rob Herring
2017-01-16 22:54 ` [PATCH v2 8/9] serdev: add a tty port controller driver Rob Herring
2017-01-18 12:42   ` Andy Shevchenko
2017-01-18 15:03     ` Rob Herring
2017-01-16 22:54 ` [PATCH v2 9/9] tty_port: register tty ports with serdev bus Rob Herring
2017-01-17 11:07 ` [PATCH v2 0/9] Serial slave device bus Pavel Machek
2017-01-20  1:36 ` msuchanek
2017-01-20  1:36   ` msuchanek
2017-01-20  9:50   ` Sebastian Reichel
2017-01-20  9:50     ` Sebastian Reichel
2017-01-20 13:44 ` Greg Kroah-Hartman
2017-01-20 13:44   ` Greg Kroah-Hartman
2017-01-20 13:55 ` Linus Walleij
2017-01-20 13:55   ` Linus Walleij
2017-01-20 14:14   ` Marcel Holtmann
2017-01-20 14:23     ` H. Nikolaus Schaller
2017-01-20 14:23       ` H. Nikolaus Schaller
2017-01-20 14:23       ` H. Nikolaus Schaller
2017-01-20 14:22   ` GPS drivers (was Re: [PATCH v2 0/9] Serial slave device bus) Pavel Machek
2017-01-20 15:26     ` Linus Walleij
2017-01-20 15:26       ` Linus Walleij
2017-01-20 16:16       ` Andy Shevchenko
2017-01-20 16:16         ` Andy Shevchenko
2017-01-27 20:02         ` Pavel Machek
2017-01-27 20:02           ` Pavel Machek
2017-01-20 20:23       ` Pavel Machek

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=20170116225436.17505-2-robh@kernel.org \
    --to=robh@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=hns@goldelico.com \
    --cc=jslaby@suse.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=loic.poulain@intel.com \
    --cc=marcel@holtmann.org \
    --cc=neil@brown.name \
    --cc=pavel@ucw.cz \
    --cc=peter@hurleysoftware.com \
    --cc=sre@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.