Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 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 | |
Alan Cox | d29f3ef | 2012-05-03 22:24:08 +0100 | [diff] [blame] | 7 | /* Legacy tty mutex glue */ |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 8 | |
| 9 | /* |
| 10 | * Getting the big tty mutex. |
| 11 | */ |
Alan Cox | d29f3ef | 2012-05-03 22:24:08 +0100 | [diff] [blame] | 12 | |
| 13 | void __lockfunc tty_lock(struct tty_struct *tty) |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 14 | { |
Alan Cox | d29f3ef | 2012-05-03 22:24:08 +0100 | [diff] [blame] | 15 | if (tty->magic != TTY_MAGIC) { |
| 16 | printk(KERN_ERR "L Bad %p\n", tty); |
| 17 | WARN_ON(1); |
| 18 | return; |
| 19 | } |
| 20 | tty_kref_get(tty); |
| 21 | mutex_lock(&tty->legacy_mutex); |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 22 | } |
| 23 | EXPORT_SYMBOL(tty_lock); |
| 24 | |
Alan Cox | d29f3ef | 2012-05-03 22:24:08 +0100 | [diff] [blame] | 25 | void __lockfunc tty_unlock(struct tty_struct *tty) |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 26 | { |
Alan Cox | d29f3ef | 2012-05-03 22:24:08 +0100 | [diff] [blame] | 27 | if (tty->magic != TTY_MAGIC) { |
| 28 | printk(KERN_ERR "U Bad %p\n", tty); |
| 29 | WARN_ON(1); |
| 30 | return; |
| 31 | } |
| 32 | mutex_unlock(&tty->legacy_mutex); |
| 33 | tty_kref_put(tty); |
Arnd Bergmann | b07471f | 2010-08-06 21:40:30 +0200 | [diff] [blame] | 34 | } |
| 35 | EXPORT_SYMBOL(tty_unlock); |
Alan Cox | d29f3ef | 2012-05-03 22:24:08 +0100 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * Getting the big tty mutex for a pair of ttys with lock ordering |
| 39 | * On a non pty/tty pair tty2 can be NULL which is just fine. |
| 40 | */ |
| 41 | void __lockfunc tty_lock_pair(struct tty_struct *tty, |
| 42 | struct tty_struct *tty2) |
| 43 | { |
| 44 | if (tty < tty2) { |
| 45 | tty_lock(tty); |
| 46 | tty_lock(tty2); |
| 47 | } else { |
| 48 | if (tty2 && tty2 != tty) |
| 49 | tty_lock(tty2); |
| 50 | tty_lock(tty); |
| 51 | } |
| 52 | } |
| 53 | EXPORT_SYMBOL(tty_lock_pair); |
| 54 | |
| 55 | void __lockfunc tty_unlock_pair(struct tty_struct *tty, |
| 56 | struct tty_struct *tty2) |
| 57 | { |
| 58 | tty_unlock(tty); |
| 59 | if (tty2 && tty2 != tty) |
| 60 | tty_unlock(tty2); |
| 61 | } |
| 62 | EXPORT_SYMBOL(tty_unlock_pair); |