diff options
author | Alan Cox <alan@linux.intel.com> | 2012-05-03 17:24:08 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-05-04 19:58:47 -0400 |
commit | d29f3ef39be4eec0362b985305fc526d9be318cf (patch) | |
tree | 35da6af15a899ca767841b864cb1ef290a0f3d4a /drivers/tty/pty.c | |
parent | d739e65bb21d34f0f5d3bf4048410e534fbec148 (diff) |
tty_lock: Localise the lock
In each remaining case the tty_lock is associated with a specific tty. This
means we can now lock on a per tty basis. We do need tty_lock_pair() for
the pty case. Uglier but still a step in the right direction.
[fixed up calls in 3 missing drivers - gregkh]
Signed-off-by: Alan Cox <alan@linux.intel.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/pty.c')
-rw-r--r-- | drivers/tty/pty.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 5505ffc91da4..d6fa8429f3ff 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,7 @@ 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_vhangup(tty->link); | 66 | tty_vhangup(tty->link); |
67 | tty_lock(); | ||
68 | } | 67 | } |
69 | } | 68 | } |
70 | 69 | ||
@@ -622,26 +621,29 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
622 | return retval; | 621 | return retval; |
623 | 622 | ||
624 | /* find a device that is not in use. */ | 623 | /* find a device that is not in use. */ |
625 | tty_lock(); | 624 | mutex_lock(&devpts_mutex); |
626 | index = devpts_new_index(inode); | 625 | index = devpts_new_index(inode); |
627 | tty_unlock(); | ||
628 | if (index < 0) { | 626 | if (index < 0) { |
629 | retval = index; | 627 | retval = index; |
630 | goto err_file; | 628 | goto err_file; |
631 | } | 629 | } |
632 | 630 | ||
631 | mutex_unlock(&devpts_mutex); | ||
632 | |||
633 | mutex_lock(&tty_mutex); | 633 | mutex_lock(&tty_mutex); |
634 | mutex_lock(&devpts_mutex); | 634 | mutex_lock(&devpts_mutex); |
635 | tty = tty_init_dev(ptm_driver, index); | 635 | tty = tty_init_dev(ptm_driver, index); |
636 | mutex_unlock(&devpts_mutex); | ||
637 | tty_lock(); | ||
638 | mutex_unlock(&tty_mutex); | ||
639 | 636 | ||
640 | if (IS_ERR(tty)) { | 637 | if (IS_ERR(tty)) { |
641 | retval = PTR_ERR(tty); | 638 | retval = PTR_ERR(tty); |
642 | goto out; | 639 | goto out; |
643 | } | 640 | } |
644 | 641 | ||
642 | /* The tty returned here is locked so we can safely | ||
643 | drop the mutex */ | ||
644 | mutex_unlock(&devpts_mutex); | ||
645 | mutex_unlock(&tty_mutex); | ||
646 | |||
645 | set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ | 647 | set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ |
646 | 648 | ||
647 | tty_add_file(tty, filp); | 649 | tty_add_file(tty, filp); |
@@ -654,16 +656,17 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
654 | if (retval) | 656 | if (retval) |
655 | goto err_release; | 657 | goto err_release; |
656 | 658 | ||
657 | tty_unlock(); | 659 | tty_unlock(tty); |
658 | return 0; | 660 | return 0; |
659 | err_release: | 661 | err_release: |
660 | tty_unlock(); | 662 | tty_unlock(tty); |
661 | tty_release(inode, filp); | 663 | tty_release(inode, filp); |
662 | return retval; | 664 | return retval; |
663 | out: | 665 | out: |
666 | mutex_unlock(&tty_mutex); | ||
664 | devpts_kill_index(inode, index); | 667 | devpts_kill_index(inode, index); |
665 | tty_unlock(); | ||
666 | err_file: | 668 | err_file: |
669 | mutex_unlock(&devpts_mutex); | ||
667 | tty_free_file(filp); | 670 | tty_free_file(filp); |
668 | return retval; | 671 | return retval; |
669 | } | 672 | } |