Merge branch 'for-next/cpus_have_const_cap' into for-next/core
[linux-2.6-block.git] / drivers / tty / tty_mutex.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
b07471fa
AB
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>
6c80c0b9 7#include "tty.h"
b07471fa 8
89c8d91e
AC
9/* Legacy tty mutex glue */
10
b07471fa
AB
11/*
12 * Getting the big tty mutex.
13 */
89c8d91e 14
c2bb524b 15void tty_lock(struct tty_struct *tty)
b07471fa 16{
89c8d91e 17 tty_kref_get(tty);
2febdb63 18 mutex_lock(&tty->legacy_mutex);
b07471fa
AB
19}
20EXPORT_SYMBOL(tty_lock);
21
0bfd464d
PH
22int tty_lock_interruptible(struct tty_struct *tty)
23{
e9036d06
PH
24 int ret;
25
0bfd464d 26 tty_kref_get(tty);
e9036d06
PH
27 ret = mutex_lock_interruptible(&tty->legacy_mutex);
28 if (ret)
29 tty_kref_put(tty);
30 return ret;
0bfd464d
PH
31}
32
c2bb524b 33void tty_unlock(struct tty_struct *tty)
b07471fa 34{
89c8d91e
AC
35 mutex_unlock(&tty->legacy_mutex);
36 tty_kref_put(tty);
b07471fa
AB
37}
38EXPORT_SYMBOL(tty_unlock);
89c8d91e 39
c2bb524b 40void tty_lock_slave(struct tty_struct *tty)
89c8d91e 41{
eef15e2a 42 if (tty && tty != tty->link)
2febdb63 43 tty_lock(tty);
89c8d91e 44}
89c8d91e 45
c2bb524b 46void tty_unlock_slave(struct tty_struct *tty)
89c8d91e 47{
2aff5e2b
PH
48 if (tty && tty != tty->link)
49 tty_unlock(tty);
89c8d91e 50}
2febdb63
PH
51
52void tty_set_lock_subclass(struct tty_struct *tty)
53{
3abf87cd 54 lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
2febdb63 55}