aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/tty_mutex.c
diff options
context:
space:
mode:
authorAlan Cox <alan@linux.intel.com>2012-05-03 17:24:08 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-05-04 19:58:47 -0400
commitd29f3ef39be4eec0362b985305fc526d9be318cf (patch)
tree35da6af15a899ca767841b864cb1ef290a0f3d4a /drivers/tty/tty_mutex.c
parentd739e65bb21d34f0f5d3bf4048410e534fbec148 (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/tty_mutex.c')
-rw-r--r--drivers/tty/tty_mutex.c60
1 files changed, 45 insertions, 15 deletions
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
index 9ff986c32a21..69adc80c98cd 100644
--- a/drivers/tty/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
@@ -4,29 +4,59 @@
4#include <linux/semaphore.h> 4#include <linux/semaphore.h>
5#include <linux/sched.h> 5#include <linux/sched.h>
6 6
7/* 7/* Legacy tty mutex glue */
8 * The 'big tty mutex'
9 *
10 * This mutex is taken and released by tty_lock() and tty_unlock(),
11 * replacing the older big kernel lock.
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);
18 8
19/* 9/*
20 * Getting the big tty mutex. 10 * Getting the big tty mutex.
21 */ 11 */
22void __lockfunc tty_lock(void) 12
13void __lockfunc tty_lock(struct tty_struct *tty)
23{ 14{
24 mutex_lock(&big_tty_mutex); 15 if (tty->magic != TTY_MAGIC) {
16 printk(KERN_ERR "L Bad %p\n", tty);
17 WARN_ON(1);
18 return;
19 }
20 tty_kref_get(tty);
21 mutex_lock(&tty->legacy_mutex);
25} 22}
26EXPORT_SYMBOL(tty_lock); 23EXPORT_SYMBOL(tty_lock);
27 24
28void __lockfunc tty_unlock(void) 25void __lockfunc tty_unlock(struct tty_struct *tty)
29{ 26{
30 mutex_unlock(&big_tty_mutex); 27 if (tty->magic != TTY_MAGIC) {
28 printk(KERN_ERR "U Bad %p\n", tty);
29 WARN_ON(1);
30 return;
31 }
32 mutex_unlock(&tty->legacy_mutex);
33 tty_kref_put(tty);
31} 34}
32EXPORT_SYMBOL(tty_unlock); 35EXPORT_SYMBOL(tty_unlock);
36
37/*
38 * Getting the big tty mutex for a pair of ttys with lock ordering
39 * On a non pty/tty pair tty2 can be NULL which is just fine.
40 */
41void __lockfunc tty_lock_pair(struct tty_struct *tty,
42 struct tty_struct *tty2)
43{
44 if (tty < tty2) {
45 tty_lock(tty);
46 tty_lock(tty2);
47 } else {
48 if (tty2 && tty2 != tty)
49 tty_lock(tty2);
50 tty_lock(tty);
51 }
52}
53EXPORT_SYMBOL(tty_lock_pair);
54
55void __lockfunc tty_unlock_pair(struct tty_struct *tty,
56 struct tty_struct *tty2)
57{
58 tty_unlock(tty);
59 if (tty2 && tty2 != tty)
60 tty_unlock(tty2);
61}
62EXPORT_SYMBOL(tty_unlock_pair);