aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/tty_mutex.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-06-02 18:21:43 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-06-02 18:21:43 -0400
commitf309532bf3e1cc1b787403d84e3039812a7dbe50 (patch)
tree6508ac81e94bfc137d1d9a55b973a2e0e0ac007b /drivers/tty/tty_mutex.c
parent233e562eac549f4f719176bbddeb50c3f17a9c8d (diff)
tty: Revert the tty locking series, it needs more work
This reverts the tty layer change to use per-tty locking, because it's not correct yet, and fixing it will require some more deep surgery. The main revert is d29f3ef39be4 ("tty_lock: Localise the lock"), but there are several smaller commits that built upon it, they also get reverted here. The list of reverted commits is: fde86d310886 - tty: add lockdep annotations 8f6576ad476b - tty: fix ldisc lock inversion trace d3ca8b64b97e - pty: Fix lock inversion b1d679afd766 - tty: drop the pty lock during hangup abcefe5fc357 - tty/amiserial: Add missing argument for tty_unlock() fd11b42e3598 - cris: fix missing tty arg in wait_event_interruptible_tty call d29f3ef39be4 - tty_lock: Localise the lock The revert had a trivial conflict in the 68360serial.c staging driver that got removed in the meantime. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/tty/tty_mutex.c')
-rw-r--r--drivers/tty/tty_mutex.c71
1 files changed, 15 insertions, 56 deletions
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
index 67feac9e6ebb..9ff986c32a21 100644
--- a/drivers/tty/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
@@ -4,70 +4,29 @@
4#include <linux/semaphore.h> 4#include <linux/semaphore.h>
5#include <linux/sched.h> 5#include <linux/sched.h>
6 6
7/* Legacy tty mutex glue */ 7/*
8 8 * The 'big tty mutex'
9enum { 9 *
10 TTY_MUTEX_NORMAL, 10 * This mutex is taken and released by tty_lock() and tty_unlock(),
11 TTY_MUTEX_NESTED, 11 * replacing the older big kernel lock.
12}; 12 * It can no longer be taken recursively, and does not get
13 * released implicitly while sleeping.
14 *
15 * Don't use in new code.
16 */
17static DEFINE_MUTEX(big_tty_mutex);
13 18
14/* 19/*
15 * Getting the big tty mutex. 20 * Getting the big tty mutex.
16 */ 21 */
17 22void __lockfunc tty_lock(void)
18static void __lockfunc tty_lock_nested(struct tty_struct *tty,
19 unsigned int subclass)
20{ 23{
21 if (tty->magic != TTY_MAGIC) { 24 mutex_lock(&big_tty_mutex);
22 printk(KERN_ERR "L Bad %p\n", tty);
23 WARN_ON(1);
24 return;
25 }
26 tty_kref_get(tty);
27 mutex_lock_nested(&tty->legacy_mutex, subclass);
28}
29
30void __lockfunc tty_lock(struct tty_struct *tty)
31{
32 return tty_lock_nested(tty, TTY_MUTEX_NORMAL);
33} 25}
34EXPORT_SYMBOL(tty_lock); 26EXPORT_SYMBOL(tty_lock);
35 27
36void __lockfunc tty_unlock(struct tty_struct *tty) 28void __lockfunc tty_unlock(void)
37{ 29{
38 if (tty->magic != TTY_MAGIC) { 30 mutex_unlock(&big_tty_mutex);
39 printk(KERN_ERR "U Bad %p\n", tty);
40 WARN_ON(1);
41 return;
42 }
43 mutex_unlock(&tty->legacy_mutex);
44 tty_kref_put(tty);
45} 31}
46EXPORT_SYMBOL(tty_unlock); 32EXPORT_SYMBOL(tty_unlock);
47
48/*
49 * Getting the big tty mutex for a pair of ttys with lock ordering
50 * On a non pty/tty pair tty2 can be NULL which is just fine.
51 */
52void __lockfunc tty_lock_pair(struct tty_struct *tty,
53 struct tty_struct *tty2)
54{
55 if (tty < tty2) {
56 tty_lock(tty);
57 tty_lock_nested(tty2, TTY_MUTEX_NESTED);
58 } else {
59 if (tty2 && tty2 != tty)
60 tty_lock(tty2);
61 tty_lock_nested(tty, TTY_MUTEX_NESTED);
62 }
63}
64EXPORT_SYMBOL(tty_lock_pair);
65
66void __lockfunc tty_unlock_pair(struct tty_struct *tty,
67 struct tty_struct *tty2)
68{
69 tty_unlock(tty);
70 if (tty2 && tty2 != tty)
71 tty_unlock(tty2);
72}
73EXPORT_SYMBOL(tty_unlock_pair);