Commit | Line | Data |
---|---|---|
b07471fa AB |
1 | #include <linux/tty.h> |
2 | #include <linux/module.h> | |
3 | #include <linux/kallsyms.h> | |
4 | #include <linux/semaphore.h> | |
5 | #include <linux/sched.h> | |
6 | ||
89c8d91e AC |
7 | /* Legacy tty mutex glue */ |
8 | ||
b07471fa AB |
9 | /* |
10 | * Getting the big tty mutex. | |
11 | */ | |
89c8d91e | 12 | |
2febdb63 | 13 | void __lockfunc tty_lock(struct tty_struct *tty) |
b07471fa | 14 | { |
6d029c68 | 15 | if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty)) |
89c8d91e | 16 | return; |
89c8d91e | 17 | tty_kref_get(tty); |
2febdb63 | 18 | mutex_lock(&tty->legacy_mutex); |
b07471fa AB |
19 | } |
20 | EXPORT_SYMBOL(tty_lock); | |
21 | ||
0bfd464d PH |
22 | int tty_lock_interruptible(struct tty_struct *tty) |
23 | { | |
e9036d06 PH |
24 | int ret; |
25 | ||
0bfd464d PH |
26 | if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty)) |
27 | return -EIO; | |
28 | tty_kref_get(tty); | |
e9036d06 PH |
29 | ret = mutex_lock_interruptible(&tty->legacy_mutex); |
30 | if (ret) | |
31 | tty_kref_put(tty); | |
32 | return ret; | |
0bfd464d PH |
33 | } |
34 | ||
89c8d91e | 35 | void __lockfunc tty_unlock(struct tty_struct *tty) |
b07471fa | 36 | { |
6d029c68 | 37 | if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty)) |
89c8d91e | 38 | return; |
89c8d91e AC |
39 | mutex_unlock(&tty->legacy_mutex); |
40 | tty_kref_put(tty); | |
b07471fa AB |
41 | } |
42 | EXPORT_SYMBOL(tty_unlock); | |
89c8d91e | 43 | |
2aff5e2b | 44 | void __lockfunc tty_lock_slave(struct tty_struct *tty) |
89c8d91e | 45 | { |
eef15e2a | 46 | if (tty && tty != tty->link) |
2febdb63 | 47 | tty_lock(tty); |
89c8d91e | 48 | } |
89c8d91e | 49 | |
2aff5e2b | 50 | void __lockfunc tty_unlock_slave(struct tty_struct *tty) |
89c8d91e | 51 | { |
2aff5e2b PH |
52 | if (tty && tty != tty->link) |
53 | tty_unlock(tty); | |
89c8d91e | 54 | } |
2febdb63 PH |
55 | |
56 | void tty_set_lock_subclass(struct tty_struct *tty) | |
57 | { | |
3abf87cd | 58 | lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE); |
2febdb63 | 59 | } |