diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2014-11-05 12:13:02 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-11-05 21:50:42 -0500 |
commit | 2febdb632bb96235b94b8fccaf882a78f8f4b2bb (patch) | |
tree | f4740b43b225a863f05df7edb59d3b3badfdb445 | |
parent | 2aff5e2bc62db43e05c814461a08aff0fc2b7fe5 (diff) |
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: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/pty.c | 2 | ||||
-rw-r--r-- | drivers/tty/tty_mutex.c | 19 | ||||
-rw-r--r-- | include/linux/tty.h | 1 |
3 files changed, 12 insertions, 10 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index bdb8fd1a2026..11db7dc8676b 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c | |||
@@ -399,6 +399,8 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, | |||
399 | if (!o_tty) | 399 | if (!o_tty) |
400 | goto err_put_module; | 400 | goto err_put_module; |
401 | 401 | ||
402 | tty_set_lock_subclass(o_tty); | ||
403 | |||
402 | if (legacy) { | 404 | if (legacy) { |
403 | /* We always use new tty termios data so we can do this | 405 | /* We always use new tty termios data so we can do this |
404 | the easy way .. */ | 406 | the easy way .. */ |
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c index f43e995c7a0f..4486741190c4 100644 --- a/drivers/tty/tty_mutex.c +++ b/drivers/tty/tty_mutex.c | |||
@@ -13,15 +13,14 @@ | |||
13 | 13 | ||
14 | enum { | 14 | enum { |
15 | TTY_MUTEX_NORMAL, | 15 | TTY_MUTEX_NORMAL, |
16 | TTY_MUTEX_NESTED, | 16 | TTY_MUTEX_SLAVE, |
17 | }; | 17 | }; |
18 | 18 | ||
19 | /* | 19 | /* |
20 | * Getting the big tty mutex. | 20 | * Getting the big tty mutex. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | static void __lockfunc tty_lock_nested(struct tty_struct *tty, | 23 | void __lockfunc tty_lock(struct tty_struct *tty) |
24 | unsigned int subclass) | ||
25 | { | 24 | { |
26 | if (tty->magic != TTY_MAGIC) { | 25 | if (tty->magic != TTY_MAGIC) { |
27 | pr_err("L Bad %p\n", tty); | 26 | pr_err("L Bad %p\n", tty); |
@@ -29,12 +28,7 @@ static void __lockfunc tty_lock_nested(struct tty_struct *tty, | |||
29 | return; | 28 | return; |
30 | } | 29 | } |
31 | tty_kref_get(tty); | 30 | tty_kref_get(tty); |
32 | mutex_lock_nested(&tty->legacy_mutex, subclass); | 31 | mutex_lock(&tty->legacy_mutex); |
33 | } | ||
34 | |||
35 | void __lockfunc tty_lock(struct tty_struct *tty) | ||
36 | { | ||
37 | return tty_lock_nested(tty, TTY_MUTEX_NORMAL); | ||
38 | } | 32 | } |
39 | EXPORT_SYMBOL(tty_lock); | 33 | EXPORT_SYMBOL(tty_lock); |
40 | 34 | ||
@@ -56,7 +50,7 @@ void __lockfunc tty_lock_slave(struct tty_struct *tty) | |||
56 | WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) || | 50 | WARN_ON(!mutex_is_locked(&tty->link->legacy_mutex) || |
57 | !tty->driver->type == TTY_DRIVER_TYPE_PTY || | 51 | !tty->driver->type == TTY_DRIVER_TYPE_PTY || |
58 | !tty->driver->type == PTY_TYPE_SLAVE); | 52 | !tty->driver->type == PTY_TYPE_SLAVE); |
59 | tty_lock_nested(tty, TTY_MUTEX_NESTED); | 53 | tty_lock(tty); |
60 | } | 54 | } |
61 | } | 55 | } |
62 | 56 | ||
@@ -65,3 +59,8 @@ void __lockfunc tty_unlock_slave(struct tty_struct *tty) | |||
65 | if (tty && tty != tty->link) | 59 | if (tty && tty != tty->link) |
66 | tty_unlock(tty); | 60 | tty_unlock(tty); |
67 | } | 61 | } |
62 | |||
63 | void tty_set_lock_subclass(struct tty_struct *tty) | ||
64 | { | ||
65 | lockdep_set_subclass(&tty->legacy_mutex, TTY_MUTEX_SLAVE); | ||
66 | } | ||
diff --git a/include/linux/tty.h b/include/linux/tty.h index a07b4b415db8..196c352a5ce8 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h | |||
@@ -640,6 +640,7 @@ extern void __lockfunc tty_lock(struct tty_struct *tty); | |||
640 | extern void __lockfunc tty_unlock(struct tty_struct *tty); | 640 | extern void __lockfunc tty_unlock(struct tty_struct *tty); |
641 | extern void __lockfunc tty_lock_slave(struct tty_struct *tty); | 641 | extern void __lockfunc tty_lock_slave(struct tty_struct *tty); |
642 | extern void __lockfunc tty_unlock_slave(struct tty_struct *tty); | 642 | extern void __lockfunc tty_unlock_slave(struct tty_struct *tty); |
643 | extern void tty_set_lock_subclass(struct tty_struct *tty); | ||
643 | /* | 644 | /* |
644 | * this shall be called only from where BTM is held (like close) | 645 | * this shall be called only from where BTM is held (like close) |
645 | * | 646 | * |