Commit 2febdb63 authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman

tty: Preset lock subclass for nested tty locks

Eliminate the requirement of specifying the tty lock nesting at
lock time; instead, set the lock subclass for slave ptys at pty
install (normal ttys and master ptys use subclass 0).
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2aff5e2b
...@@ -399,6 +399,8 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, ...@@ -399,6 +399,8 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
if (!o_tty) if (!o_tty)
goto err_put_module; goto err_put_module;
tty_set_lock_subclass(o_tty);
if (legacy) { if (legacy) {
/* We always use new tty termios data so we can do this /* We always use new tty termios data so we can do this
the easy way .. */ the easy way .. */
......
...@@ -13,15 +13,14 @@ ...@@ -13,15 +13,14 @@
enum { enum {
TTY_MUTEX_NORMAL, TTY_MUTEX_NORMAL,
TTY_MUTEX_NESTED, TTY_MUTEX_SLAVE,
}; };
/* /*
* Getting the big tty mutex. * Getting the big tty mutex.
*/ */
static void __lockfunc tty_lock_nested(struct tty_struct *tty, void __lockfunc tty_lock(struct tty_struct *tty)
unsigned int subclass)
{ {
if (tty->magic != TTY_MAGIC) { if (tty->magic != TTY_MAGIC) {
pr_err("L Bad %p\n", tty); pr_err("L Bad %p\n", tty);
...@@ -29,12 +28,7 @@ static void __lockfunc tty_lock_nested(struct tty_struct *tty, ...@@ -29,12 +28,7 @@ static void __lockfunc tty_lock_nested(struct tty_struct *tty,
return; return;
} }
tty_kref_get(tty); tty_kref_get(tty);
mutex_lock_nested(&tty->legacy_mutex, subclass); mutex_lock(&tty->legacy_mutex);
}
void __lockfunc tty_lock(struct tty_struct *tty)
{
return tty_lock_nested(tty, TTY_MUTEX_NORMAL);
} }
EXPORT_SYMBOL(tty_lock); EXPORT_SYMBOL(tty_lock);
...@@ -56,7 +50,7 @@ void __lockfunc tty_lock_slave(struct tty_struct *tty) ...@@ -56,7 +50,7 @@ void __lockfunc tty_lock_slave(struct tty_struct *tty)
WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) || WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) ||
!tty->driver->type == TTY_DRIVER_TYPE_PTY || !tty->driver->type == TTY_DRIVER_TYPE_PTY ||
!tty->driver->type == PTY_TYPE_SLAVE); !tty->driver->type == PTY_TYPE_SLAVE);
tty_lock_nested(tty, TTY_MUTEX_NESTED); tty_lock(tty);
} }
} }
...@@ -65,3 +59,8 @@ void __lockfunc tty_unlock_slave(struct tty_struct *tty) ...@@ -65,3 +59,8 @@ void __lockfunc tty_unlock_slave(struct tty_struct *tty)
if (tty && tty != tty->link) if (tty && tty != tty->link)
tty_unlock(tty); tty_unlock(tty);
} }
void tty_set_lock_subclass(struct tty_struct *tty)
{
lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE);
}
...@@ -640,6 +640,7 @@ extern void __lockfunc tty_lock(struct tty_struct *tty); ...@@ -640,6 +640,7 @@ extern void __lockfunc tty_lock(struct tty_struct *tty);
extern void __lockfunc tty_unlock(struct tty_struct *tty); extern void __lockfunc tty_unlock(struct tty_struct *tty);
extern void __lockfunc tty_lock_slave(struct tty_struct *tty); extern void __lockfunc tty_lock_slave(struct tty_struct *tty);
extern void __lockfunc tty_unlock_slave(struct tty_struct *tty); extern void __lockfunc tty_unlock_slave(struct tty_struct *tty);
extern void tty_set_lock_subclass(struct tty_struct *tty);
/* /*
* this shall be called only from where BTM is held (like close) * this shall be called only from where BTM is held (like close)
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment