Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 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 | |||||
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 7 | /* Legacy tty mutex glue */ |
8 | |||||
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 9 | /* |
10 | * Getting the big tty mutex. | ||||
11 | */ | ||||
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 12 | |
Peter Hurley | 2febdb6 | 2014-11-05 12:13:02 -0500 | [diff] [blame] | 13 | void __lockfunc tty_lock(struct tty_struct *tty) |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 14 | { |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 15 | if (tty->magic != TTY_MAGIC) { |
Sangho Yi | 7a0c4ed | 2012-10-18 00:15:13 +0900 | [diff] [blame] | 16 | pr_err("L Bad %p\n", tty); |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 17 | WARN_ON(1); |
18 | return; | ||||
19 | } | ||||
20 | tty_kref_get(tty); | ||||
Peter Hurley | 2febdb6 | 2014-11-05 12:13:02 -0500 | [diff] [blame] | 21 | mutex_lock(&tty->legacy_mutex); |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 22 | } |
23 | EXPORT_SYMBOL(tty_lock); | ||||
24 | |||||
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 25 | void __lockfunc tty_unlock(struct tty_struct *tty) |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 26 | { |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 27 | if (tty->magic != TTY_MAGIC) { |
Sangho Yi | 7a0c4ed | 2012-10-18 00:15:13 +0900 | [diff] [blame] | 28 | pr_err("U Bad %p\n", tty); |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 29 | WARN_ON(1); |
30 | return; | ||||
31 | } | ||||
32 | mutex_unlock(&tty->legacy_mutex); | ||||
33 | tty_kref_put(tty); | ||||
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 34 | } |
35 | EXPORT_SYMBOL(tty_unlock); | ||||
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 36 | |
Peter Hurley | 2aff5e2 | 2014-11-05 12:13:01 -0500 | [diff] [blame] | 37 | void __lockfunc tty_lock_slave(struct tty_struct *tty) |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 38 | { |
Peter Hurley | eef15e2 | 2014-12-30 07:11:11 -0500 | [diff] [blame] | 39 | if (tty && tty != tty->link) |
Peter Hurley | 2febdb6 | 2014-11-05 12:13:02 -0500 | [diff] [blame] | 40 | tty_lock(tty); |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 41 | } |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 42 | |
Peter Hurley | 2aff5e2 | 2014-11-05 12:13:01 -0500 | [diff] [blame] | 43 | void __lockfunc tty_unlock_slave(struct tty_struct *tty) |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 44 | { |
Peter Hurley | 2aff5e2 | 2014-11-05 12:13:01 -0500 | [diff] [blame] | 45 | if (tty && tty != tty->link) |
46 | tty_unlock(tty); | ||||
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 47 | } |
Peter Hurley | 2febdb6 | 2014-11-05 12:13:02 -0500 | [diff] [blame] | 48 | |
49 | void tty_set_lock_subclass(struct tty_struct *tty) | ||||
50 | { | ||||
Peter Hurley | 3abf87c | 2015-01-17 15:42:04 -0500 | [diff] [blame] | 51 | lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE); |
Peter Hurley | 2febdb6 | 2014-11-05 12:13:02 -0500 | [diff] [blame] | 52 | } |