1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 296fd7ce5SGreg Kroah-Hartman #include <linux/tty.h> 396fd7ce5SGreg Kroah-Hartman #include <linux/module.h> 496fd7ce5SGreg Kroah-Hartman #include <linux/kallsyms.h> 596fd7ce5SGreg Kroah-Hartman #include <linux/semaphore.h> 696fd7ce5SGreg Kroah-Hartman #include <linux/sched.h> 7*6c80c0b9SGreg Kroah-Hartman #include "tty.h" 896fd7ce5SGreg Kroah-Hartman 989c8d91eSAlan Cox /* Legacy tty mutex glue */ 1089c8d91eSAlan Cox 1196fd7ce5SGreg Kroah-Hartman /* 1296fd7ce5SGreg Kroah-Hartman * Getting the big tty mutex. 1396fd7ce5SGreg Kroah-Hartman */ 1489c8d91eSAlan Cox tty_lock(struct tty_struct * tty)15c2bb524bSPeter Hurleyvoid tty_lock(struct tty_struct *tty) 1696fd7ce5SGreg Kroah-Hartman { 1789c8d91eSAlan Cox tty_kref_get(tty); 182febdb63SPeter Hurley mutex_lock(&tty->legacy_mutex); 1996fd7ce5SGreg Kroah-Hartman } 2096fd7ce5SGreg Kroah-Hartman EXPORT_SYMBOL(tty_lock); 2196fd7ce5SGreg Kroah-Hartman tty_lock_interruptible(struct tty_struct * tty)220bfd464dSPeter Hurleyint tty_lock_interruptible(struct tty_struct *tty) 230bfd464dSPeter Hurley { 24e9036d06SPeter Hurley int ret; 25e9036d06SPeter Hurley 260bfd464dSPeter Hurley tty_kref_get(tty); 27e9036d06SPeter Hurley ret = mutex_lock_interruptible(&tty->legacy_mutex); 28e9036d06SPeter Hurley if (ret) 29e9036d06SPeter Hurley tty_kref_put(tty); 30e9036d06SPeter Hurley return ret; 310bfd464dSPeter Hurley } 320bfd464dSPeter Hurley tty_unlock(struct tty_struct * tty)33c2bb524bSPeter Hurleyvoid tty_unlock(struct tty_struct *tty) 3496fd7ce5SGreg Kroah-Hartman { 3589c8d91eSAlan Cox mutex_unlock(&tty->legacy_mutex); 3689c8d91eSAlan Cox tty_kref_put(tty); 3796fd7ce5SGreg Kroah-Hartman } 3896fd7ce5SGreg Kroah-Hartman EXPORT_SYMBOL(tty_unlock); 3989c8d91eSAlan Cox tty_lock_slave(struct tty_struct * tty)40c2bb524bSPeter Hurleyvoid tty_lock_slave(struct tty_struct *tty) 4189c8d91eSAlan Cox { 42eef15e2aSPeter Hurley if (tty && tty != tty->link) 432febdb63SPeter Hurley tty_lock(tty); 4489c8d91eSAlan Cox } 4589c8d91eSAlan Cox tty_unlock_slave(struct tty_struct * tty)46c2bb524bSPeter Hurleyvoid tty_unlock_slave(struct tty_struct *tty) 4789c8d91eSAlan Cox { 482aff5e2bSPeter Hurley if (tty && tty != tty->link) 4989c8d91eSAlan Cox tty_unlock(tty); 5089c8d91eSAlan Cox } 512febdb63SPeter Hurley tty_set_lock_subclass(struct tty_struct * tty)522febdb63SPeter Hurleyvoid tty_set_lock_subclass(struct tty_struct *tty) 532febdb63SPeter Hurley { 543abf87cdSPeter Hurley lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE); 552febdb63SPeter Hurley } 56