Merge branch 'tty-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[pandora-kernel.git] / drivers / tty / pty.c
index e809e9d..e18604b 100644 (file)
@@ -670,12 +670,18 @@ static int ptmx_open(struct inode *inode, struct file *filp)
 
        nonseekable_open(inode, filp);
 
+       retval = tty_alloc_file(filp);
+       if (retval)
+               return retval;
+
        /* find a device that is not in use. */
        tty_lock();
        index = devpts_new_index(inode);
        tty_unlock();
-       if (index < 0)
-               return index;
+       if (index < 0) {
+               retval = index;
+               goto err_file;
+       }
 
        mutex_lock(&tty_mutex);
        tty_lock();
@@ -689,27 +695,27 @@ static int ptmx_open(struct inode *inode, struct file *filp)
 
        set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
 
-       retval = tty_add_file(tty, filp);
-       if (retval)
-               goto out;
+       tty_add_file(tty, filp);
 
        retval = devpts_pty_new(inode, tty->link);
        if (retval)
-               goto out1;
+               goto err_release;
 
        retval = ptm_driver->ops->open(tty, filp);
        if (retval)
-               goto out2;
-out1:
+               goto err_release;
+
        tty_unlock();
-       return retval;
-out2:
+       return 0;
+err_release:
        tty_unlock();
        tty_release(inode, filp);
        return retval;
 out:
        devpts_kill_index(inode, index);
        tty_unlock();
+err_file:
+       tty_free_file(filp);
        return retval;
 }