xref: /openbmc/linux/drivers/tty/tty_mutex.c (revision 6d029c68)
196fd7ce5SGreg Kroah-Hartman #include <linux/tty.h>
296fd7ce5SGreg Kroah-Hartman #include <linux/module.h>
396fd7ce5SGreg Kroah-Hartman #include <linux/kallsyms.h>
496fd7ce5SGreg Kroah-Hartman #include <linux/semaphore.h>
596fd7ce5SGreg Kroah-Hartman #include <linux/sched.h>
696fd7ce5SGreg Kroah-Hartman 
789c8d91eSAlan Cox /* Legacy tty mutex glue */
889c8d91eSAlan Cox 
996fd7ce5SGreg Kroah-Hartman /*
1096fd7ce5SGreg Kroah-Hartman  * Getting the big tty mutex.
1196fd7ce5SGreg Kroah-Hartman  */
1289c8d91eSAlan Cox 
132febdb63SPeter Hurley void __lockfunc tty_lock(struct tty_struct *tty)
1496fd7ce5SGreg Kroah-Hartman {
156d029c68SPeter Hurley 	if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
1689c8d91eSAlan Cox 		return;
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 
2289c8d91eSAlan Cox void __lockfunc tty_unlock(struct tty_struct *tty)
2396fd7ce5SGreg Kroah-Hartman {
246d029c68SPeter Hurley 	if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))
2589c8d91eSAlan Cox 		return;
2689c8d91eSAlan Cox 	mutex_unlock(&tty->legacy_mutex);
2789c8d91eSAlan Cox 	tty_kref_put(tty);
2896fd7ce5SGreg Kroah-Hartman }
2996fd7ce5SGreg Kroah-Hartman EXPORT_SYMBOL(tty_unlock);
3089c8d91eSAlan Cox 
312aff5e2bSPeter Hurley void __lockfunc tty_lock_slave(struct tty_struct *tty)
3289c8d91eSAlan Cox {
33eef15e2aSPeter Hurley 	if (tty && tty != tty->link)
342febdb63SPeter Hurley 		tty_lock(tty);
3589c8d91eSAlan Cox }
3689c8d91eSAlan Cox 
372aff5e2bSPeter Hurley void __lockfunc tty_unlock_slave(struct tty_struct *tty)
3889c8d91eSAlan Cox {
392aff5e2bSPeter Hurley 	if (tty && tty != tty->link)
4089c8d91eSAlan Cox 		tty_unlock(tty);
4189c8d91eSAlan Cox }
422febdb63SPeter Hurley 
432febdb63SPeter Hurley void tty_set_lock_subclass(struct tty_struct *tty)
442febdb63SPeter Hurley {
453abf87cdSPeter Hurley 	lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
462febdb63SPeter Hurley }
47