aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/pty.c
diff options
context:
space:
mode:
authorAlan Cox <alan@linux.intel.com>2012-06-29 09:48:36 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-06 17:24:52 -0400
commitf5e3bcc504c3c35cc6e06a9ee42efed7c274066b (patch)
tree267e2679b28ee3991621f0a675c0092cfe82a426 /drivers/tty/pty.c
parent0a44ab41eb833d07e3ec807d87151c7164d4f075 (diff)
tty: localise the lock
The termios and other changes mean the other protections needed on the driver tty arrays should be adequate. Turn it all back on. This contains pieces folded in from the fixes made to the original patches | From: Geert Uytterhoeven <geert@linux-m68k.org> (fix m68k) | From: Paul Gortmaker <paul.gortmaker@windriver.com> (fix cris) | From: Jiri Kosina <jkosina@suze.cz> (lockdep) | From: Eric Dumazet <eric.dumazet@gmail.com> (lockdep) Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/pty.c')
-rw-r--r--drivers/tty/pty.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index b50fc1c01415..d8558834ce57 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -47,6 +47,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
47 wake_up_interruptible(&tty->read_wait); 47 wake_up_interruptible(&tty->read_wait);
48 wake_up_interruptible(&tty->write_wait); 48 wake_up_interruptible(&tty->write_wait);
49 tty->packet = 0; 49 tty->packet = 0;
50 /* Review - krefs on tty_link ?? */
50 if (!tty->link) 51 if (!tty->link)
51 return; 52 return;
52 tty->link->packet = 0; 53 tty->link->packet = 0;
@@ -62,9 +63,9 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
62 mutex_unlock(&devpts_mutex); 63 mutex_unlock(&devpts_mutex);
63 } 64 }
64#endif 65#endif
65 tty_unlock(); 66 tty_unlock(tty);
66 tty_vhangup(tty->link); 67 tty_vhangup(tty->link);
67 tty_lock(); 68 tty_lock(tty);
68 } 69 }
69} 70}
70 71
@@ -615,26 +616,27 @@ static int ptmx_open(struct inode *inode, struct file *filp)
615 return retval; 616 return retval;
616 617
617 /* find a device that is not in use. */ 618 /* find a device that is not in use. */
618 tty_lock(); 619 mutex_lock(&devpts_mutex);
619 index = devpts_new_index(inode); 620 index = devpts_new_index(inode);
620 tty_unlock();
621 if (index < 0) { 621 if (index < 0) {
622 retval = index; 622 retval = index;
623 goto err_file; 623 goto err_file;
624 } 624 }
625 625
626 mutex_unlock(&devpts_mutex);
627
626 mutex_lock(&tty_mutex); 628 mutex_lock(&tty_mutex);
627 mutex_lock(&devpts_mutex);
628 tty = tty_init_dev(ptm_driver, index); 629 tty = tty_init_dev(ptm_driver, index);
629 mutex_unlock(&devpts_mutex);
630 tty_lock();
631 mutex_unlock(&tty_mutex);
632 630
633 if (IS_ERR(tty)) { 631 if (IS_ERR(tty)) {
634 retval = PTR_ERR(tty); 632 retval = PTR_ERR(tty);
635 goto out; 633 goto out;
636 } 634 }
637 635
636 /* The tty returned here is locked so we can safely
637 drop the mutex */
638 mutex_unlock(&tty_mutex);
639
638 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 640 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
639 641
640 tty_add_file(tty, filp); 642 tty_add_file(tty, filp);
@@ -647,16 +649,17 @@ static int ptmx_open(struct inode *inode, struct file *filp)
647 if (retval) 649 if (retval)
648 goto err_release; 650 goto err_release;
649 651
650 tty_unlock(); 652 tty_unlock(tty);
651 return 0; 653 return 0;
652err_release: 654err_release:
653 tty_unlock(); 655 tty_unlock(tty);
654 tty_release(inode, filp); 656 tty_release(inode, filp);
655 return retval; 657 return retval;
656out: 658out:
659 mutex_unlock(&tty_mutex);
657 devpts_kill_index(inode, index); 660 devpts_kill_index(inode, index);
658 tty_unlock();
659err_file: 661err_file:
662 mutex_unlock(&devpts_mutex);
660 tty_free_file(filp); 663 tty_free_file(filp);
661 return retval; 664 return retval;
662} 665}