tty: serial: 8250: drop owner assignment from platform_drivers
[deliverable/linux.git] / drivers / tty / tty_mutex.c
... / ...
CommitLineData
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 * Nested tty locks are necessary for releasing pty pairs.
9 * The stable lock order is master pty first, then slave pty.
10 */
11
12/* Legacy tty mutex glue */
13
14enum {
15 TTY_MUTEX_NORMAL,
16 TTY_MUTEX_SLAVE,
17};
18
19/*
20 * Getting the big tty mutex.
21 */
22
23void __lockfunc tty_lock(struct tty_struct *tty)
24{
25 if (tty->magic != TTY_MAGIC) {
26 pr_err("L Bad %p\n", tty);
27 WARN_ON(1);
28 return;
29 }
30 tty_kref_get(tty);
31 mutex_lock(&tty->legacy_mutex);
32}
33EXPORT_SYMBOL(tty_lock);
34
35void __lockfunc tty_unlock(struct tty_struct *tty)
36{
37 if (tty->magic != TTY_MAGIC) {
38 pr_err("U Bad %p\n", tty);
39 WARN_ON(1);
40 return;
41 }
42 mutex_unlock(&tty->legacy_mutex);
43 tty_kref_put(tty);
44}
45EXPORT_SYMBOL(tty_unlock);
46
47void __lockfunc tty_lock_slave(struct tty_struct *tty)
48{
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);
54 }
55}
56
57void __lockfunc tty_unlock_slave(struct tty_struct *tty)
58{
59 if (tty && tty != tty->link)
60 tty_unlock(tty);
61}
62
63void tty_set_lock_subclass(struct tty_struct *tty)
64{
65 lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE);
66}
This page took 0.023643 seconds and 5 git commands to generate.