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 | ||
2aff5e2b PH |
7 | /* |
8 | * Nested tty locks are necessary for releasing pty pairs. | |
9 | * The stable lock order is master pty first, then slave pty. | |
10 | */ | |
11 | ||
89c8d91e AC |
12 | /* Legacy tty mutex glue */ |
13 | ||
14 | enum { | |
15 | TTY_MUTEX_NORMAL, | |
2febdb63 | 16 | TTY_MUTEX_SLAVE, |
89c8d91e | 17 | }; |
fde86d31 | 18 | |
b07471fa AB |
19 | /* |
20 | * Getting the big tty mutex. | |
21 | */ | |
89c8d91e | 22 | |
2febdb63 | 23 | void __lockfunc tty_lock(struct tty_struct *tty) |
b07471fa | 24 | { |
89c8d91e | 25 | if (tty->magic != TTY_MAGIC) { |
7a0c4eda | 26 | pr_err("L Bad %p\n", tty); |
89c8d91e AC |
27 | WARN_ON(1); |
28 | return; | |
29 | } | |
30 | tty_kref_get(tty); | |
2febdb63 | 31 | mutex_lock(&tty->legacy_mutex); |
b07471fa AB |
32 | } |
33 | EXPORT_SYMBOL(tty_lock); | |
34 | ||
89c8d91e | 35 | void __lockfunc tty_unlock(struct tty_struct *tty) |
b07471fa | 36 | { |
89c8d91e | 37 | if (tty->magic != TTY_MAGIC) { |
7a0c4eda | 38 | pr_err("U Bad %p\n", tty); |
89c8d91e AC |
39 | WARN_ON(1); |
40 | return; | |
41 | } | |
42 | mutex_unlock(&tty->legacy_mutex); | |
43 | tty_kref_put(tty); | |
b07471fa AB |
44 | } |
45 | EXPORT_SYMBOL(tty_unlock); | |
89c8d91e | 46 | |
2aff5e2b | 47 | void __lockfunc tty_lock_slave(struct tty_struct *tty) |
89c8d91e | 48 | { |
2aff5e2b PH |
49 | if (tty && tty != tty->link) { |
50 | WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) || | |
51 | !tty->driver->type == TTY_DRIVER_TYPE_PTY || | |
52 | !tty->driver->type == PTY_TYPE_SLAVE); | |
2febdb63 | 53 | tty_lock(tty); |
89c8d91e AC |
54 | } |
55 | } | |
89c8d91e | 56 | |
2aff5e2b | 57 | void __lockfunc tty_unlock_slave(struct tty_struct *tty) |
89c8d91e | 58 | { |
2aff5e2b PH |
59 | if (tty && tty != tty->link) |
60 | tty_unlock(tty); | |
89c8d91e | 61 | } |
2febdb63 PH |
62 | |
63 | void tty_set_lock_subclass(struct tty_struct *tty) | |
64 | { | |
65 | lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE); | |
66 | } |