WIP FPC-III support
[linux/fpc-iii.git] / drivers / tty / tty_mutex.c
blob2640635ee177d1ad027ee7bc3443bfb2880ae17c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/tty.h>
3 #include <linux/module.h>
4 #include <linux/kallsyms.h>
5 #include <linux/semaphore.h>
6 #include <linux/sched.h>
8 /* Legacy tty mutex glue */
11 * Getting the big tty mutex.
14 void tty_lock(struct tty_struct *tty)
16 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
17 return;
18 tty_kref_get(tty);
19 mutex_lock(&tty->legacy_mutex);
21 EXPORT_SYMBOL(tty_lock);
23 int tty_lock_interruptible(struct tty_struct *tty)
25 int ret;
27 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
28 return -EIO;
29 tty_kref_get(tty);
30 ret = mutex_lock_interruptible(&tty->legacy_mutex);
31 if (ret)
32 tty_kref_put(tty);
33 return ret;
36 void tty_unlock(struct tty_struct *tty)
38 if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))
39 return;
40 mutex_unlock(&tty->legacy_mutex);
41 tty_kref_put(tty);
43 EXPORT_SYMBOL(tty_unlock);
45 void tty_lock_slave(struct tty_struct *tty)
47 if (tty && tty != tty->link)
48 tty_lock(tty);
51 void tty_unlock_slave(struct tty_struct *tty)
53 if (tty && tty != tty->link)
54 tty_unlock(tty);
57 void tty_set_lock_subclass(struct tty_struct *tty)
59 lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);