Skip to content

Commit

Permalink
tty: Preset lock subclass for nested tty locks
Browse files Browse the repository at this point in the history
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: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Peter Hurley authored and Greg Kroah-Hartman committed Nov 6, 2014
1 parent 2aff5e2 commit 2febdb6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions drivers/tty/pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
if (!o_tty)
goto err_put_module;

tty_set_lock_subclass(o_tty);

if (legacy) {
/* We always use new tty termios data so we can do this
the easy way .. */
Expand Down
19 changes: 9 additions & 10 deletions drivers/tty/tty_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,22 @@

enum {
TTY_MUTEX_NORMAL,
TTY_MUTEX_NESTED,
TTY_MUTEX_SLAVE,
};

/*
* 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);
WARN_ON(1);
return;
}
tty_kref_get(tty);
mutex_lock_nested(&tty->legacy_mutex, subclass);
}

void __lockfunc tty_lock(struct tty_struct *tty)
{
return tty_lock_nested(tty, TTY_MUTEX_NORMAL);
mutex_lock(&tty->legacy_mutex);
}
EXPORT_SYMBOL(tty_lock);

Expand All @@ -56,7 +50,7 @@ void __lockfunc tty_lock_slave(struct tty_struct *tty)
WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) ||
!tty->driver->type == TTY_DRIVER_TYPE_PTY ||
!tty->driver->type == PTY_TYPE_SLAVE);
tty_lock_nested(tty, TTY_MUTEX_NESTED);
tty_lock(tty);
}
}

Expand All @@ -65,3 +59,8 @@ 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)
{
lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE);
}
1 change: 1 addition & 0 deletions include/linux/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_lock_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)
*
Expand Down

0 comments on commit 2febdb6

Please sign in to comment.