UPSTREAM: drm/edid: Extract SADs properly from multiple audio data blocks
[firefly-linux-kernel-4.4.55.git] / drivers / tty / tty_mutex.c
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
7 /* Legacy tty mutex glue */
8
9 /*
10  * Getting the big tty mutex.
11  */
12
13 void __lockfunc tty_lock(struct tty_struct *tty)
14 {
15         if (tty->magic != TTY_MAGIC) {
16                 pr_err("L Bad %p\n", tty);
17                 WARN_ON(1);
18                 return;
19         }
20         tty_kref_get(tty);
21         mutex_lock(&tty->legacy_mutex);
22 }
23 EXPORT_SYMBOL(tty_lock);
24
25 int tty_lock_interruptible(struct tty_struct *tty)
26 {
27         if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
28                 return -EIO;
29         tty_kref_get(tty);
30         return mutex_lock_interruptible(&tty->legacy_mutex);
31 }
32
33 void __lockfunc tty_unlock(struct tty_struct *tty)
34 {
35         if (tty->magic != TTY_MAGIC) {
36                 pr_err("U Bad %p\n", tty);
37                 WARN_ON(1);
38                 return;
39         }
40         mutex_unlock(&tty->legacy_mutex);
41         tty_kref_put(tty);
42 }
43 EXPORT_SYMBOL(tty_unlock);
44
45 void __lockfunc tty_lock_slave(struct tty_struct *tty)
46 {
47         if (tty && tty != tty->link)
48                 tty_lock(tty);
49 }
50
51 void __lockfunc tty_unlock_slave(struct tty_struct *tty)
52 {
53         if (tty && tty != tty->link)
54                 tty_unlock(tty);
55 }
56
57 void tty_set_lock_subclass(struct tty_struct *tty)
58 {
59         lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
60 }