diff options
author | Alan Cox <alan@linux.intel.com> | 2012-05-03 17:22:09 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-05-04 19:48:37 -0400 |
commit | d739e65bb21d34f0f5d3bf4048410e534fbec148 (patch) | |
tree | 4a64becf77444c5b269449cd99bc4bbe31175e7d /drivers | |
parent | 3af502b96649ccb7462da73b0cca446c8384b155 (diff) |
pty: Lock the devpts bits privately
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | 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 eeae7fafe9a7..5505ffc91da4 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c | |||
@@ -26,11 +26,13 @@ | |||
26 | #include <linux/bitops.h> | 26 | #include <linux/bitops.h> |
27 | #include <linux/devpts_fs.h> | 27 | #include <linux/devpts_fs.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/mutex.h> | ||
29 | 30 | ||
30 | 31 | ||
31 | #ifdef CONFIG_UNIX98_PTYS | 32 | #ifdef CONFIG_UNIX98_PTYS |
32 | static struct tty_driver *ptm_driver; | 33 | static struct tty_driver *ptm_driver; |
33 | static struct tty_driver *pts_driver; | 34 | static struct tty_driver *pts_driver; |
35 | static DEFINE_MUTEX(devpts_mutex); | ||
34 | #endif | 36 | #endif |
35 | 37 | ||
36 | static void pty_close(struct tty_struct *tty, struct file *filp) | 38 | 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) | |||
54 | if (tty->driver->subtype == PTY_TYPE_MASTER) { | 56 | if (tty->driver->subtype == PTY_TYPE_MASTER) { |
55 | set_bit(TTY_OTHER_CLOSED, &tty->flags); | 57 | set_bit(TTY_OTHER_CLOSED, &tty->flags); |
56 | #ifdef CONFIG_UNIX98_PTYS | 58 | #ifdef CONFIG_UNIX98_PTYS |
57 | if (tty->driver == ptm_driver) | 59 | if (tty->driver == ptm_driver) { |
60 | mutex_lock(&devpts_mutex); | ||
58 | devpts_pty_kill(tty->link); | 61 | devpts_pty_kill(tty->link); |
62 | mutex_unlock(&devpts_mutex); | ||
63 | } | ||
59 | #endif | 64 | #endif |
60 | tty_unlock(); | 65 | tty_unlock(); |
61 | tty_vhangup(tty->link); | 66 | tty_vhangup(tty->link); |
@@ -475,13 +480,17 @@ static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, | |||
475 | * @idx: tty index | 480 | * @idx: tty index |
476 | * | 481 | * |
477 | * Look up a pty master device. Called under the tty_mutex for now. | 482 | * Look up a pty master device. Called under the tty_mutex for now. |
478 | * This provides our locking. | 483 | * This provides our locking for the tty pointer. |
479 | */ | 484 | */ |
480 | 485 | ||
481 | static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, | 486 | static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, |
482 | struct inode *pts_inode, int idx) | 487 | struct inode *pts_inode, int idx) |
483 | { | 488 | { |
484 | struct tty_struct *tty = devpts_get_tty(pts_inode, idx); | 489 | struct tty_struct *tty; |
490 | |||
491 | mutex_lock(&devpts_mutex); | ||
492 | tty = devpts_get_tty(pts_inode, idx); | ||
493 | mutex_unlock(&devpts_mutex); | ||
485 | /* Master must be open before slave */ | 494 | /* Master must be open before slave */ |
486 | if (!tty) | 495 | if (!tty) |
487 | return ERR_PTR(-EIO); | 496 | return ERR_PTR(-EIO); |
@@ -622,8 +631,10 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
622 | } | 631 | } |
623 | 632 | ||
624 | mutex_lock(&tty_mutex); | 633 | mutex_lock(&tty_mutex); |
625 | tty_lock(); | 634 | mutex_lock(&devpts_mutex); |
626 | tty = tty_init_dev(ptm_driver, index); | 635 | tty = tty_init_dev(ptm_driver, index); |
636 | mutex_unlock(&devpts_mutex); | ||
637 | tty_lock(); | ||
627 | mutex_unlock(&tty_mutex); | 638 | mutex_unlock(&tty_mutex); |
628 | 639 | ||
629 | if (IS_ERR(tty)) { | 640 | if (IS_ERR(tty)) { |