blob: 0efcf713b756e5e7eaf95bf7b5f2a744fc7f6dc0 [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{
Alan Cox89c8d912012-08-08 16:30:13 +010015 if (tty->magic != TTY_MAGIC) {
Sangho Yi7a0c4ed2012-10-18 00:15:13 +090016 pr_err("L Bad %p\n", tty);
Alan Cox89c8d912012-08-08 16:30:13 +010017 WARN_ON(1);
18 return;
19 }
20 tty_kref_get(tty);
Peter Hurley2febdb62014-11-05 12:13:02 -050021 mutex_lock(&tty->legacy_mutex);
Arnd Bergmannb07471f2010-08-06 21:40:30 +020022}
23EXPORT_SYMBOL(tty_lock);
24
Alan Cox89c8d912012-08-08 16:30:13 +010025void __lockfunc tty_unlock(struct tty_struct *tty)
Arnd Bergmannb07471f2010-08-06 21:40:30 +020026{
Alan Cox89c8d912012-08-08 16:30:13 +010027 if (tty->magic != TTY_MAGIC) {
Sangho Yi7a0c4ed2012-10-18 00:15:13 +090028 pr_err("U Bad %p\n", tty);
Alan Cox89c8d912012-08-08 16:30:13 +010029 WARN_ON(1);
30 return;
31 }
32 mutex_unlock(&tty->legacy_mutex);
33 tty_kref_put(tty);
Arnd Bergmannb07471f2010-08-06 21:40:30 +020034}
35EXPORT_SYMBOL(tty_unlock);
Alan Cox89c8d912012-08-08 16:30:13 +010036
Peter Hurley2aff5e22014-11-05 12:13:01 -050037void __lockfunc tty_lock_slave(struct tty_struct *tty)
Alan Cox89c8d912012-08-08 16:30:13 +010038{
Peter Hurleyeef15e22014-12-30 07:11:11 -050039 if (tty && tty != tty->link)
Peter Hurley2febdb62014-11-05 12:13:02 -050040 tty_lock(tty);
Alan Cox89c8d912012-08-08 16:30:13 +010041}
Alan Cox89c8d912012-08-08 16:30:13 +010042
Peter Hurley2aff5e22014-11-05 12:13:01 -050043void __lockfunc tty_unlock_slave(struct tty_struct *tty)
Alan Cox89c8d912012-08-08 16:30:13 +010044{
Peter Hurley2aff5e22014-11-05 12:13:01 -050045 if (tty && tty != tty->link)
46 tty_unlock(tty);
Alan Cox89c8d912012-08-08 16:30:13 +010047}
Peter Hurley2febdb62014-11-05 12:13:02 -050048
49void tty_set_lock_subclass(struct tty_struct *tty)
50{
Peter Hurley3abf87c2015-01-17 15:42:04 -050051 lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE);
Peter Hurley2febdb62014-11-05 12:13:02 -050052}