Branch data Line data Source code
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 : : enum {
10 : : TTY_MUTEX_NORMAL,
11 : : TTY_MUTEX_NESTED,
12 : : };
13 : :
14 : : /*
15 : : * Getting the big tty mutex.
16 : : */
17 : :
18 : 0 : static void __lockfunc tty_lock_nested(struct tty_struct *tty,
19 : : unsigned int subclass)
20 : : {
21 [ - + ]: 10728 : if (tty->magic != TTY_MAGIC) {
22 : 0 : pr_err("L Bad %p\n", tty);
23 : 0 : WARN_ON(1);
24 : 10728 : return;
25 : : }
26 : : tty_kref_get(tty);
27 : 10728 : mutex_lock_nested(&tty->legacy_mutex, subclass);
28 : : }
29 : :
30 : 0 : void __lockfunc tty_lock(struct tty_struct *tty)
31 : : {
32 : 8258 : return tty_lock_nested(tty, TTY_MUTEX_NORMAL);
33 : : }
34 : : EXPORT_SYMBOL(tty_lock);
35 : :
36 : 0 : void __lockfunc tty_unlock(struct tty_struct *tty)
37 : : {
38 [ - + ]: 10728 : if (tty->magic != TTY_MAGIC) {
39 : 0 : pr_err("U Bad %p\n", tty);
40 : 0 : WARN_ON(1);
41 : 0 : return;
42 : : }
43 : 10728 : mutex_unlock(&tty->legacy_mutex);
44 : 10728 : tty_kref_put(tty);
45 : : }
46 : : EXPORT_SYMBOL(tty_unlock);
47 : :
48 : : /*
49 : : * Getting the big tty mutex for a pair of ttys with lock ordering
50 : : * On a non pty/tty pair tty2 can be NULL which is just fine.
51 : : */
52 : 0 : void __lockfunc tty_lock_pair(struct tty_struct *tty,
53 : : struct tty_struct *tty2)
54 : : {
55 [ + + ]: 2470 : if (tty < tty2) {
56 : : tty_lock(tty);
57 : 1667 : tty_lock_nested(tty2, TTY_MUTEX_NESTED);
58 : : } else {
59 [ + + ]: 803 : if (tty2 && tty2 != tty)
60 : : tty_lock(tty2);
61 : 803 : tty_lock_nested(tty, TTY_MUTEX_NESTED);
62 : : }
63 : 2470 : }
64 : : EXPORT_SYMBOL(tty_lock_pair);
65 : :
66 : 0 : void __lockfunc tty_unlock_pair(struct tty_struct *tty,
67 : : struct tty_struct *tty2)
68 : : {
69 : 2470 : tty_unlock(tty);
70 [ + + ]: 2470 : if (tty2 && tty2 != tty)
71 : 1800 : tty_unlock(tty2);
72 : 0 : }
73 : : EXPORT_SYMBOL(tty_unlock_pair);
|