OSDN Git Service

ARM: dts: at91: sama5d3: define clock rate range for tcb1
[sagit-ice-cold/kernel_xiaomi_msm8998.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         int ret;
28
29         if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
30                 return -EIO;
31         tty_kref_get(tty);
32         ret = mutex_lock_interruptible(&tty->legacy_mutex);
33         if (ret)
34                 tty_kref_put(tty);
35         return ret;
36 }
37
38 void __lockfunc tty_unlock(struct tty_struct *tty)
39 {
40         if (tty->magic != TTY_MAGIC) {
41                 pr_err("U Bad %p\n", tty);
42                 WARN_ON(1);
43                 return;
44         }
45         mutex_unlock(&tty->legacy_mutex);
46         tty_kref_put(tty);
47 }
48 EXPORT_SYMBOL(tty_unlock);
49
50 void __lockfunc tty_lock_slave(struct tty_struct *tty)
51 {
52         if (tty && tty != tty->link)
53                 tty_lock(tty);
54 }
55
56 void __lockfunc tty_unlock_slave(struct tty_struct *tty)
57 {
58         if (tty && tty != tty->link)
59                 tty_unlock(tty);
60 }
61
62 void tty_set_lock_subclass(struct tty_struct *tty)
63 {
64         lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
65 }