tty: Preset lock subclass for nested tty locks
authorPeter Hurley <peter@hurleysoftware.com>
Wed, 5 Nov 2014 17:13:02 +0000 (12:13 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 6 Nov 2014 02:50:42 +0000 (18:50 -0800)
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>
drivers/tty/pty.c
drivers/tty/tty_mutex.c
include/linux/tty.h

index bdb8fd1a202682e6e0eaf057c3cc88685c6ebc03..11db7dc8676b6d493cbf1acfd35039a730f8205b 100644 (file)
@@ -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 .. */
index f43e995c7a0fc8a64ae1ee41eb2c7afa418df5b4..4486741190c47d52d8079f360081d99085ce82c4 100644 (file)
 
 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);
@@ -29,12 +28,7 @@ static void __lockfunc tty_lock_nested(struct tty_struct *tty,
                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);
 
@@ -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);
        }
 }
 
@@ -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);
+}
index a07b4b415db89958b2df8a4930a25b15cc852aeb..196c352a5ce89ab4cdccd633d6ad14913059e924 100644 (file)
@@ -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)
  *
This page took 0.04224 seconds and 5 git commands to generate.