0001
0002 #include <linux/tty.h>
0003 #include <linux/module.h>
0004 #include <linux/kallsyms.h>
0005 #include <linux/semaphore.h>
0006 #include <linux/sched.h>
0007 #include "tty.h"
0008
0009
0010
0011
0012
0013
0014
0015 void tty_lock(struct tty_struct *tty)
0016 {
0017 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
0018 return;
0019 tty_kref_get(tty);
0020 mutex_lock(&tty->legacy_mutex);
0021 }
0022 EXPORT_SYMBOL(tty_lock);
0023
0024 int tty_lock_interruptible(struct tty_struct *tty)
0025 {
0026 int ret;
0027
0028 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
0029 return -EIO;
0030 tty_kref_get(tty);
0031 ret = mutex_lock_interruptible(&tty->legacy_mutex);
0032 if (ret)
0033 tty_kref_put(tty);
0034 return ret;
0035 }
0036
0037 void tty_unlock(struct tty_struct *tty)
0038 {
0039 if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))
0040 return;
0041 mutex_unlock(&tty->legacy_mutex);
0042 tty_kref_put(tty);
0043 }
0044 EXPORT_SYMBOL(tty_unlock);
0045
0046 void tty_lock_slave(struct tty_struct *tty)
0047 {
0048 if (tty && tty != tty->link)
0049 tty_lock(tty);
0050 }
0051
0052 void tty_unlock_slave(struct tty_struct *tty)
0053 {
0054 if (tty && tty != tty->link)
0055 tty_unlock(tty);
0056 }
0057
0058 void tty_set_lock_subclass(struct tty_struct *tty)
0059 {
0060 lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
0061 }