Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm...
[firefly-linux-kernel-4.4.55.git] / drivers / tty / pty.c
index 7a1a53819e22ca5f7ec29bb6c52db8a7fe8e61fd..a9d256d6e909c1aecfc854732694d608256aeb15 100644 (file)
@@ -53,6 +53,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
        /* Review - krefs on tty_link ?? */
        if (!tty->link)
                return;
+       tty_flush_to_ldisc(tty->link);
        set_bit(TTY_OTHER_CLOSED, &tty->link->flags);
        wake_up_interruptible(&tty->link->read_wait);
        wake_up_interruptible(&tty->link->write_wait);
@@ -66,9 +67,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
                        mutex_unlock(&devpts_mutex);
                }
 #endif
-               tty_unlock(tty);
                tty_vhangup(tty->link);
-               tty_lock(tty);
        }
 }
 
@@ -383,6 +382,10 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
        int idx = tty->index;
        int retval = -ENOMEM;
 
+       /* Opening the slave first has always returned -EIO */
+       if (driver->subtype != PTY_TYPE_MASTER)
+               return -EIO;
+
        ports[0] = kmalloc(sizeof **ports, GFP_KERNEL);
        ports[1] = kmalloc(sizeof **ports, GFP_KERNEL);
        if (!ports[0] || !ports[1])
@@ -395,6 +398,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 .. */
@@ -419,8 +424,6 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
         * Everything allocated ... set up the o_tty structure.
         */
        tty_driver_kref_get(driver->other);
-       if (driver->subtype == PTY_TYPE_MASTER)
-               o_tty->count++;
        /* Establish the links in both directions */
        tty->link   = o_tty;
        o_tty->link = tty;
@@ -432,6 +435,7 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
 
        tty_driver_kref_get(driver);
        tty->count++;
+       o_tty->count++;
        return 0;
 err_free_termios:
        if (legacy)