From daf1eb3fc2e4c7be9f722500687ac4c8062d614d Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 3 May 2012 22:22:09 +0100 Subject: [PATCH] --- yaml --- r: 304217 b: refs/heads/master c: d739e65bb21d34f0f5d3bf4048410e534fbec148 h: refs/heads/master i: 304215: fecb188926a9c658b480d6194d961bbd820a3054 v: v3 --- [refs] | 2 +- trunk/drivers/tty/pty.c | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/[refs] b/[refs] index 0f1d0d7f3821..522c72f16052 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 3af502b96649ccb7462da73b0cca446c8384b155 +refs/heads/master: d739e65bb21d34f0f5d3bf4048410e534fbec148 diff --git a/trunk/drivers/tty/pty.c b/trunk/drivers/tty/pty.c index eeae7fafe9a7..5505ffc91da4 100644 --- a/trunk/drivers/tty/pty.c +++ b/trunk/drivers/tty/pty.c @@ -26,11 +26,13 @@ #include #include #include +#include #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)) {