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