Merge tag 'spi-v3.20' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
[linux/fpc-iii.git] / drivers / tty / tty_mutex.c
blob4486741190c47d52d8079f360081d99085ce82c4
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>
7 /*
8 * Nested tty locks are necessary for releasing pty pairs.
9 * The stable lock order is master pty first, then slave pty.
12 /* Legacy tty mutex glue */
14 enum {
15 TTY_MUTEX_NORMAL,
16 TTY_MUTEX_SLAVE,
20 * Getting the big tty mutex.
23 void __lockfunc tty_lock(struct tty_struct *tty)
25 if (tty->magic != TTY_MAGIC) {
26 pr_err("L Bad %p\n", tty);
27 WARN_ON(1);
28 return;
30 tty_kref_get(tty);
31 mutex_lock(&tty->legacy_mutex);
33 EXPORT_SYMBOL(tty_lock);
35 void __lockfunc tty_unlock(struct tty_struct *tty)
37 if (tty->magic != TTY_MAGIC) {
38 pr_err("U Bad %p\n", tty);
39 WARN_ON(1);
40 return;
42 mutex_unlock(&tty->legacy_mutex);
43 tty_kref_put(tty);
45 EXPORT_SYMBOL(tty_unlock);
47 void __lockfunc tty_lock_slave(struct tty_struct *tty)
49 if (tty && tty != tty->link) {
50 WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) ||
51 !tty->driver->type == TTY_DRIVER_TYPE_PTY ||
52 !tty->driver->type == PTY_TYPE_SLAVE);
53 tty_lock(tty);
57 void __lockfunc tty_unlock_slave(struct tty_struct *tty)
59 if (tty && tty != tty->link)
60 tty_unlock(tty);
63 void tty_set_lock_subclass(struct tty_struct *tty)
65 lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE);