Message ID | 20190108202811.12136-3-gpiccoli@canonical.com |
---|---|
State | New |
Headers | show |
Series | Line discipline buffer flush/tty_reopen() race fix | expand |
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 67e2ea4e7f1d..83e57a328f2b 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1267,15 +1267,20 @@ static int tty_reopen(struct tty_struct *tty) if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) return -EBUSY; - tty->count++; + retval = tty_ldisc_lock(tty, 5 * HZ); + if (retval) + return retval; + tty->count++; if (tty->ldisc) - return 0; + goto out_unlock; retval = tty_ldisc_reinit(tty, tty->termios.c_line); if (retval) tty->count--; +out_unlock: + tty_ldisc_unlock(tty); return retval; }