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 /* Legacy tty mutex glue */ 8 9 /* 10 * Getting the big tty mutex. 11 */ 12 13 void tty_lock(struct tty_struct *tty) 14 { 15 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty)) 16 return; 17 tty_kref_get(tty); 18 mutex_lock(&tty->legacy_mutex); 19 } 20 EXPORT_SYMBOL(tty_lock); 21 22 int tty_lock_interruptible(struct tty_struct *tty) 23 { 24 int ret; 25 26 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty)) 27 return -EIO; 28 tty_kref_get(tty); 29 ret = mutex_lock_interruptible(&tty->legacy_mutex); 30 if (ret) 31 tty_kref_put(tty); 32 return ret; 33 } 34 35 void tty_unlock(struct tty_struct *tty) 36 { 37 if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty)) 38 return; 39 mutex_unlock(&tty->legacy_mutex); 40 tty_kref_put(tty); 41 } 42 EXPORT_SYMBOL(tty_unlock); 43 44 void tty_lock_slave(struct tty_struct *tty) 45 { 46 if (tty && tty != tty->link) 47 tty_lock(tty); 48 } 49 50 void tty_unlock_slave(struct tty_struct *tty) 51 { 52 if (tty && tty != tty->link) 53 tty_unlock(tty); 54 } 55 56 void tty_set_lock_subclass(struct tty_struct *tty) 57 { 58 lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE); 59 } 60