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 | c2bb524 | 2016-01-09 21:13:51 -0800 | [diff] [blame] | 13 | void tty_lock(struct tty_struct *tty) |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 14 | { |
Peter Hurley | 6d029c6 | 2015-11-08 13:01:20 -0500 | [diff] [blame] | 15 | if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty)) |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 16 | return; |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 17 | tty_kref_get(tty); |
Peter Hurley | 2febdb6 | 2014-11-05 12:13:02 -0500 | [diff] [blame] | 18 | mutex_lock(&tty->legacy_mutex); |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 19 | } |
20 | EXPORT_SYMBOL(tty_lock); | ||||
21 | |||||
Peter Hurley | 0bfd464 | 2016-01-09 21:13:44 -0800 | [diff] [blame] | 22 | int tty_lock_interruptible(struct tty_struct *tty) |
23 | { | ||||
Peter Hurley | e9036d0 | 2016-02-05 10:49:36 -0800 | [diff] [blame] | 24 | int ret; |
25 | |||||
Peter Hurley | 0bfd464 | 2016-01-09 21:13:44 -0800 | [diff] [blame] | 26 | if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty)) |
27 | return -EIO; | ||||
28 | tty_kref_get(tty); | ||||
Peter Hurley | e9036d0 | 2016-02-05 10:49:36 -0800 | [diff] [blame] | 29 | ret = mutex_lock_interruptible(&tty->legacy_mutex); |
30 | if (ret) | ||||
31 | tty_kref_put(tty); | ||||
32 | return ret; | ||||
Peter Hurley | 0bfd464 | 2016-01-09 21:13:44 -0800 | [diff] [blame] | 33 | } |
34 | |||||
Peter Hurley | c2bb524 | 2016-01-09 21:13:51 -0800 | [diff] [blame] | 35 | void tty_unlock(struct tty_struct *tty) |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 36 | { |
Peter Hurley | 6d029c6 | 2015-11-08 13:01:20 -0500 | [diff] [blame] | 37 | if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty)) |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 38 | return; |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 39 | mutex_unlock(&tty->legacy_mutex); |
40 | tty_kref_put(tty); | ||||
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 41 | } |
42 | EXPORT_SYMBOL(tty_unlock); | ||||
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 43 | |
Peter Hurley | c2bb524 | 2016-01-09 21:13:51 -0800 | [diff] [blame] | 44 | void tty_lock_slave(struct tty_struct *tty) |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 45 | { |
Peter Hurley | eef15e2 | 2014-12-30 07:11:11 -0500 | [diff] [blame] | 46 | if (tty && tty != tty->link) |
Peter Hurley | 2febdb6 | 2014-11-05 12:13:02 -0500 | [diff] [blame] | 47 | tty_lock(tty); |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 48 | } |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 49 | |
Peter Hurley | c2bb524 | 2016-01-09 21:13:51 -0800 | [diff] [blame] | 50 | void tty_unlock_slave(struct tty_struct *tty) |
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 51 | { |
Peter Hurley | 2aff5e2 | 2014-11-05 12:13:01 -0500 | [diff] [blame] | 52 | if (tty && tty != tty->link) |
53 | tty_unlock(tty); | ||||
Alan Cox | 89c8d91 | 2012-08-08 16:30:13 +0100 | [diff] [blame] | 54 | } |
Peter Hurley | 2febdb6 | 2014-11-05 12:13:02 -0500 | [diff] [blame] | 55 | |
56 | void tty_set_lock_subclass(struct tty_struct *tty) | ||||
57 | { | ||||
Peter Hurley | 3abf87c | 2015-01-17 15:42:04 -0500 | [diff] [blame] | 58 | lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE); |
Peter Hurley | 2febdb6 | 2014-11-05 12:13:02 -0500 | [diff] [blame] | 59 | } |