--- zzzz-none-000/linux-3.10.107/drivers/tty/tty_mutex.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/tty/tty_mutex.c 2021-02-04 17:41:59.000000000 +0000 @@ -6,17 +6,11 @@ /* Legacy tty mutex glue */ -enum { - TTY_MUTEX_NORMAL, - TTY_MUTEX_NESTED, -}; - /* * Getting the big tty mutex. */ -static void __lockfunc tty_lock_nested(struct tty_struct *tty, - unsigned int subclass) +void __lockfunc tty_lock(struct tty_struct *tty) { if (tty->magic != TTY_MAGIC) { pr_err("L Bad %p\n", tty); @@ -24,14 +18,17 @@ return; } tty_kref_get(tty); - mutex_lock_nested(&tty->legacy_mutex, subclass); + mutex_lock(&tty->legacy_mutex); } +EXPORT_SYMBOL(tty_lock); -void __lockfunc tty_lock(struct tty_struct *tty) +int tty_lock_interruptible(struct tty_struct *tty) { - return tty_lock_nested(tty, TTY_MUTEX_NORMAL); + if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty)) + return -EIO; + tty_kref_get(tty); + return mutex_lock_interruptible(&tty->legacy_mutex); } -EXPORT_SYMBOL(tty_lock); void __lockfunc tty_unlock(struct tty_struct *tty) { @@ -45,29 +42,19 @@ } EXPORT_SYMBOL(tty_unlock); -/* - * Getting the big tty mutex for a pair of ttys with lock ordering - * On a non pty/tty pair tty2 can be NULL which is just fine. - */ -void __lockfunc tty_lock_pair(struct tty_struct *tty, - struct tty_struct *tty2) +void __lockfunc tty_lock_slave(struct tty_struct *tty) { - if (tty < tty2) { + if (tty && tty != tty->link) tty_lock(tty); - tty_lock_nested(tty2, TTY_MUTEX_NESTED); - } else { - if (tty2 && tty2 != tty) - tty_lock(tty2); - tty_lock_nested(tty, TTY_MUTEX_NESTED); - } } -EXPORT_SYMBOL(tty_lock_pair); -void __lockfunc tty_unlock_pair(struct tty_struct *tty, - struct tty_struct *tty2) +void __lockfunc tty_unlock_slave(struct tty_struct *tty) +{ + if (tty && tty != tty->link) + tty_unlock(tty); +} + +void tty_set_lock_subclass(struct tty_struct *tty) { - tty_unlock(tty); - if (tty2 && tty2 != tty) - tty_unlock(tty2); + lockdep_set_subclass(&tty->legacy_mutex, TTY_LOCK_SLAVE); } -EXPORT_SYMBOL(tty_unlock_pair);