]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/tty/tty_mutex.c
serial: samsung: Fix ERR pointer dereference on deferred probe
[mirror_ubuntu-zesty-kernel.git] / drivers / tty / tty_mutex.c
CommitLineData
b07471fa
AB
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
89c8d91e
AC
7/* Legacy tty mutex glue */
8
b07471fa
AB
9/*
10 * Getting the big tty mutex.
11 */
89c8d91e 12
2febdb63 13void __lockfunc tty_lock(struct tty_struct *tty)
b07471fa 14{
89c8d91e 15 if (tty->magic != TTY_MAGIC) {
7a0c4eda 16 pr_err("L Bad %p\n", tty);
89c8d91e
AC
17 WARN_ON(1);
18 return;
19 }
20 tty_kref_get(tty);
2febdb63 21 mutex_lock(&tty->legacy_mutex);
b07471fa
AB
22}
23EXPORT_SYMBOL(tty_lock);
24
c35f1234
PH
25int tty_lock_interruptible(struct tty_struct *tty)
26{
27 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
28 return -EIO;
29 tty_kref_get(tty);
30 return mutex_lock_interruptible(&tty->legacy_mutex);
31}
32
89c8d91e 33void __lockfunc tty_unlock(struct tty_struct *tty)
b07471fa 34{
89c8d91e 35 if (tty->magic != TTY_MAGIC) {
7a0c4eda 36 pr_err("U Bad %p\n", tty);
89c8d91e
AC
37 WARN_ON(1);
38 return;
39 }
40 mutex_unlock(&tty->legacy_mutex);
41 tty_kref_put(tty);
b07471fa
AB
42}
43EXPORT_SYMBOL(tty_unlock);
89c8d91e 44
2aff5e2b 45void __lockfunc tty_lock_slave(struct tty_struct *tty)
89c8d91e 46{
eef15e2a 47 if (tty && tty != tty->link)
2febdb63 48 tty_lock(tty);
89c8d91e 49}
89c8d91e 50
2aff5e2b 51void __lockfunc tty_unlock_slave(struct tty_struct *tty)
89c8d91e 52{
2aff5e2b
PH
53 if (tty && tty != tty->link)
54 tty_unlock(tty);
89c8d91e 55}
2febdb63
PH
56
57void tty_set_lock_subclass(struct tty_struct *tty)
58{
3abf87cd 59 lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
2febdb63 60}