tty: double unlock on error in ptmx_open()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 11 Jul 2012 06:40:40 +0000 (09:40 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Jul 2012 21:27:08 +0000 (14:27 -0700)
The problem here is that we called mutex_unlock(&devpts_mutex) on the
error path when we weren't holding the lock.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/pty.c

index d8558834ce572d8e46f830f8042917d417aefe08..a0ca0830cbcf28d73842ae7e914f9ea5c345a168 100644 (file)
@@ -618,13 +618,12 @@ static int ptmx_open(struct inode *inode, struct file *filp)
        /* find a device that is not in use. */
        mutex_lock(&devpts_mutex);
        index = devpts_new_index(inode);
+       mutex_unlock(&devpts_mutex);
        if (index < 0) {
                retval = index;
                goto err_file;
        }
 
-       mutex_unlock(&devpts_mutex);
-
        mutex_lock(&tty_mutex);
        tty = tty_init_dev(ptm_driver, index);
 
@@ -659,7 +658,6 @@ out:
        mutex_unlock(&tty_mutex);
        devpts_kill_index(inode, index);
 err_file:
-        mutex_unlock(&devpts_mutex);
        tty_free_file(filp);
        return retval;
 }