Loading...
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/*
8 * The 'big tty mutex'
9 *
10 * This mutex is taken and released by tty_lock() and tty_unlock(),
11 * replacing the older big kernel lock.
12 * It can no longer be taken recursively, and does not get
13 * released implicitly while sleeping.
14 *
15 * Don't use in new code.
16 */
17static DEFINE_MUTEX(big_tty_mutex);
18struct task_struct *__big_tty_mutex_owner;
19EXPORT_SYMBOL_GPL(__big_tty_mutex_owner);
20
21/*
22 * Getting the big tty mutex.
23 */
24void __lockfunc tty_lock(void)
25{
26 struct task_struct *task = current;
27
28 WARN_ON(__big_tty_mutex_owner == task);
29
30 mutex_lock(&big_tty_mutex);
31 __big_tty_mutex_owner = task;
32}
33EXPORT_SYMBOL(tty_lock);
34
35void __lockfunc tty_unlock(void)
36{
37 struct task_struct *task = current;
38
39 WARN_ON(__big_tty_mutex_owner != task);
40 __big_tty_mutex_owner = NULL;
41
42 mutex_unlock(&big_tty_mutex);
43}
44EXPORT_SYMBOL(tty_unlock);
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"
8
9/* Legacy tty mutex glue */
10
11/*
12 * Getting the big tty mutex.
13 */
14
15void tty_lock(struct tty_struct *tty)
16{
17 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
18 return;
19 tty_kref_get(tty);
20 mutex_lock(&tty->legacy_mutex);
21}
22EXPORT_SYMBOL(tty_lock);
23
24int tty_lock_interruptible(struct tty_struct *tty)
25{
26 int ret;
27
28 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
29 return -EIO;
30 tty_kref_get(tty);
31 ret = mutex_lock_interruptible(&tty->legacy_mutex);
32 if (ret)
33 tty_kref_put(tty);
34 return ret;
35}
36
37void tty_unlock(struct tty_struct *tty)
38{
39 if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))
40 return;
41 mutex_unlock(&tty->legacy_mutex);
42 tty_kref_put(tty);
43}
44EXPORT_SYMBOL(tty_unlock);
45
46void tty_lock_slave(struct tty_struct *tty)
47{
48 if (tty && tty != tty->link)
49 tty_lock(tty);
50}
51
52void tty_unlock_slave(struct tty_struct *tty)
53{
54 if (tty && tty != tty->link)
55 tty_unlock(tty);
56}
57
58void tty_set_lock_subclass(struct tty_struct *tty)
59{
60 lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
61}