Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / tty / tty_mutex.c
blob784e46a0a3b1013d9eaf07f50d9ce8c4bd882fa7
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>
7 #include "tty.h"
9 /* Legacy tty mutex glue */
12 * Getting the big tty mutex.
15 void tty_lock(struct tty_struct *tty)
17 tty_kref_get(tty);
18 mutex_lock(&tty->legacy_mutex);
20 EXPORT_SYMBOL(tty_lock);
22 int tty_lock_interruptible(struct tty_struct *tty)
24 int ret;
26 tty_kref_get(tty);
27 ret = mutex_lock_interruptible(&tty->legacy_mutex);
28 if (ret)
29 tty_kref_put(tty);
30 return ret;
33 void tty_unlock(struct tty_struct *tty)
35 mutex_unlock(&tty->legacy_mutex);
36 tty_kref_put(tty);
38 EXPORT_SYMBOL(tty_unlock);
40 void tty_lock_slave(struct tty_struct *tty)
42 if (tty && tty != tty->link)
43 tty_lock(tty);
46 void tty_unlock_slave(struct tty_struct *tty)
48 if (tty && tty != tty->link)
49 tty_unlock(tty);
52 void tty_set_lock_subclass(struct tty_struct *tty)
54 lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);