Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[firefly-linux-kernel-4.4.55.git] / drivers / tty / tty_ldisc.c
index 6368dd95e13740ffd52f4a54e65ed11179ca41b0..3737f55272d2c1184463edc3714f89fb2724730e 100644 (file)
@@ -397,19 +397,17 @@ static void __lockfunc tty_ldisc_unlock_pair(struct tty_struct *tty,
  *     tty_ldisc_flush -       flush line discipline queue
  *     @tty: tty
  *
- *     Flush the line discipline queue (if any) for this tty. If there
- *     is no line discipline active this is a no-op.
+ *     Flush the line discipline queue (if any) and the tty flip buffers
+ *     for this tty.
  */
 
 void tty_ldisc_flush(struct tty_struct *tty)
 {
        struct tty_ldisc *ld = tty_ldisc_ref(tty);
-       if (ld) {
-               if (ld->ops->flush_buffer)
-                       ld->ops->flush_buffer(tty);
+
+       tty_buffer_flush(tty, ld);
+       if (ld)
                tty_ldisc_deref(ld);
-       }
-       tty_buffer_flush(tty);
 }
 EXPORT_SYMBOL_GPL(tty_ldisc_flush);
 
@@ -574,8 +572,11 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
                tty_ldisc_restore(tty, old_ldisc);
        }
 
-       if (tty->ldisc->ops->num != old_ldisc->ops->num && tty->ops->set_ldisc)
+       if (tty->ldisc->ops->num != old_ldisc->ops->num && tty->ops->set_ldisc) {
+               down_read(&tty->termios_rwsem);
                tty->ops->set_ldisc(tty);
+               up_read(&tty->termios_rwsem);
+       }
 
        /* At this point we hold a reference to the new ldisc and a
           reference to the old ldisc, or we hold two references to