pty: Fix buffer flush deadlock
[firefly-linux-kernel-4.4.55.git] / drivers / tty / pty.c
index f882ac81b93a2d54a602bf8c21d84a60f182ca47..0e273158edacc8d115d1247733d956fcfa9ed6a3 100644 (file)
@@ -212,10 +212,16 @@ static int pty_signal(struct tty_struct *tty, int sig)
 static void pty_flush_buffer(struct tty_struct *tty)
 {
        struct tty_struct *to = tty->link;
+       struct tty_ldisc *ld;
 
        if (!to)
                return;
-       /* tty_buffer_flush(to); FIXME */
+
+       ld = tty_ldisc_ref(to);
+       tty_buffer_flush(to, ld);
+       if (ld)
+               tty_ldisc_deref(ld);
+
        if (to->packet) {
                spin_lock_irq(&tty->ctrl_lock);
                tty->ctrl_status |= TIOCPKT_FLUSHWRITE;
@@ -425,6 +431,8 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
        tty->port = ports[1];
        o_tty->port->itty = o_tty;
 
+       tty_buffer_set_lock_subclass(o_tty->port);
+
        tty_driver_kref_get(driver);
        tty->count++;
        o_tty->count++;