pty: Hold ctrl_lock for packet mode updates
[firefly-linux-kernel-4.4.55.git] / drivers / tty / pty.c
index e554393d5551192997dc1048194b76bcc70b62e4..7a1a53819e22ca5f7ec29bb6c52db8a7fe8e61fd 100644 (file)
@@ -47,7 +47,9 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
        set_bit(TTY_IO_ERROR, &tty->flags);
        wake_up_interruptible(&tty->read_wait);
        wake_up_interruptible(&tty->write_wait);
+       spin_lock_irq(&tty->ctrl_lock);
        tty->packet = 0;
+       spin_unlock_irq(&tty->ctrl_lock);
        /* Review - krefs on tty_link ?? */
        if (!tty->link)
                return;
@@ -186,8 +188,9 @@ static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
        spin_lock_irq(&tty->ctrl_lock);
        if (pktmode) {
                if (!tty->packet) {
-                       tty->packet = 1;
                        tty->link->ctrl_status = 0;
+                       smp_mb();
+                       tty->packet = 1;
                }
        } else
                tty->packet = 0;