From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: [PATCH 2/3] pty: Lock the devpts bits privately
Date: Thu, 03 May 2012 22:22:09 +0100 [thread overview]
Message-ID: <20120503212205.568.25804.stgit@bob.linux.org.uk> (raw)
In-Reply-To: <20120503212151.568.91854.stgit@bob.linux.org.uk>
From: Alan Cox <alan@linux.intel.com>
This is a private pty affair, we don't want to tangle it with the tty_lock
any more as we know all the other non tty locking is now handled by the vfs
so we too can move.
Signed-off-by: Alan Cox <alan@linux.intel.com>
---
drivers/tty/pty.c | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index eeae7fa..5505ffc 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -26,11 +26,13 @@
#include <linux/bitops.h>
#include <linux/devpts_fs.h>
#include <linux/slab.h>
+#include <linux/mutex.h>
#ifdef CONFIG_UNIX98_PTYS
static struct tty_driver *ptm_driver;
static struct tty_driver *pts_driver;
+static DEFINE_MUTEX(devpts_mutex);
#endif
static void pty_close(struct tty_struct *tty, struct file *filp)
@@ -54,8 +56,11 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
if (tty->driver->subtype == PTY_TYPE_MASTER) {
set_bit(TTY_OTHER_CLOSED, &tty->flags);
#ifdef CONFIG_UNIX98_PTYS
- if (tty->driver == ptm_driver)
+ if (tty->driver == ptm_driver) {
+ mutex_lock(&devpts_mutex);
devpts_pty_kill(tty->link);
+ mutex_unlock(&devpts_mutex);
+ }
#endif
tty_unlock();
tty_vhangup(tty->link);
@@ -475,13 +480,17 @@ static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
* @idx: tty index
*
* Look up a pty master device. Called under the tty_mutex for now.
- * This provides our locking.
+ * This provides our locking for the tty pointer.
*/
static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
struct inode *pts_inode, int idx)
{
- struct tty_struct *tty = devpts_get_tty(pts_inode, idx);
+ struct tty_struct *tty;
+
+ mutex_lock(&devpts_mutex);
+ tty = devpts_get_tty(pts_inode, idx);
+ mutex_unlock(&devpts_mutex);
/* Master must be open before slave */
if (!tty)
return ERR_PTR(-EIO);
@@ -622,8 +631,10 @@ static int ptmx_open(struct inode *inode, struct file *filp)
}
mutex_lock(&tty_mutex);
- tty_lock();
+ mutex_lock(&devpts_mutex);
tty = tty_init_dev(ptm_driver, index);
+ mutex_unlock(&devpts_mutex);
+ tty_lock();
mutex_unlock(&tty_mutex);
if (IS_ERR(tty)) {
next prev parent reply other threads:[~2012-05-03 21:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-03 21:21 [PATCH 1/3] tty_lock: undo the old tty_lock use on the ctty Alan Cox
2012-05-03 21:22 ` Alan Cox [this message]
2012-05-08 18:18 ` [PATCH 2/3] pty: Lock the devpts bits privately H. Peter Anvin
2012-05-08 20:43 ` Alan Cox
2012-05-08 20:41 ` H. Peter Anvin
2012-05-03 21:24 ` [PATCH 3/3] tty_lock: Localise the lock Alan Cox
2012-05-04 20:48 ` Arnd Bergmann
2012-05-04 23:54 ` Greg KH
2012-05-04 23:55 ` Greg KH
2012-05-07 16:03 ` Sasha Levin
2012-05-07 16:11 ` Alan Cox
2012-05-07 16:30 ` Sasha Levin
2012-05-07 16:42 ` Alan Cox
2012-05-07 17:00 ` Sasha Levin
2012-05-07 21:04 ` Jiri Slaby
2012-05-08 18:12 ` Sasha Levin
2012-05-11 10:40 ` Sasha Levin
2012-05-11 14:52 ` Greg KH
2012-05-11 15:09 ` Sasha Levin
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=20120503212205.568.25804.stgit@bob.linux.org.uk \
--to=alan@lxorguk.ukuu.org.uk \
--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).