blob: 77703a3912075a7b740eb4626a5159d55ea6f57a [file] [log] [blame]
Arnd Bergmannb07471f2010-08-06 21:40:30 +02001#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
Alan Cox89c8d912012-08-08 16:30:13 +01007/* Legacy tty mutex glue */
8
Arnd Bergmannb07471f2010-08-06 21:40:30 +02009/*
10 * Getting the big tty mutex.
11 */
Alan Cox89c8d912012-08-08 16:30:13 +010012
Peter Hurley2febdb62014-11-05 12:13:02 -050013void __lockfunc tty_lock(struct tty_struct *tty)
Arnd Bergmannb07471f2010-08-06 21:40:30 +020014{
Peter Hurley6d029c62015-11-08 13:01:20 -050015 if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
Alan Cox89c8d912012-08-08 16:30:13 +010016 return;
Alan Cox89c8d912012-08-08 16:30:13 +010017 tty_kref_get(tty);
Peter Hurley2febdb62014-11-05 12:13:02 -050018 mutex_lock(&tty->legacy_mutex);
Arnd Bergmannb07471f2010-08-06 21:40:30 +020019}
20EXPORT_SYMBOL(tty_lock);
21
Alan Cox89c8d912012-08-08 16:30:13 +010022void __lockfunc tty_unlock(struct tty_struct *tty)
Arnd Bergmannb07471f2010-08-06 21:40:30 +020023{
Peter Hurley6d029c62015-11-08 13:01:20 -050024 if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))
Alan Cox89c8d912012-08-08 16:30:13 +010025 return;
Alan Cox89c8d912012-08-08 16:30:13 +010026 mutex_unlock(&tty->legacy_mutex);
27 tty_kref_put(tty);
Arnd Bergmannb07471f2010-08-06 21:40:30 +020028}
29EXPORT_SYMBOL(tty_unlock);
Alan Cox89c8d912012-08-08 16:30:13 +010030
Peter Hurley2aff5e22014-11-05 12:13:01 -050031void __lockfunc tty_lock_slave(struct tty_struct *tty)
Alan Cox89c8d912012-08-08 16:30:13 +010032{
Peter Hurleyeef15e22014-12-30 07:11:11 -050033 if (tty && tty != tty->link)
Peter Hurley2febdb62014-11-05 12:13:02 -050034 tty_lock(tty);
Alan Cox89c8d912012-08-08 16:30:13 +010035}
Alan Cox89c8d912012-08-08 16:30:13 +010036
Peter Hurley2aff5e22014-11-05 12:13:01 -050037void __lockfunc tty_unlock_slave(struct tty_struct *tty)
Alan Cox89c8d912012-08-08 16:30:13 +010038{
Peter Hurley2aff5e22014-11-05 12:13:01 -050039 if (tty && tty != tty->link)
40 tty_unlock(tty);
Alan Cox89c8d912012-08-08 16:30:13 +010041}
Peter Hurley2febdb62014-11-05 12:13:02 -050042
43void tty_set_lock_subclass(struct tty_struct *tty)
44{
Peter Hurley3abf87c2015-01-17 15:42:04 -050045 lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
Peter Hurley2febdb62014-11-05 12:13:02 -050046}