Message ID | 20190108201849.11907-4-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 d2f00378fc18..3784f55f3dc9 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1486,15 +1486,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; }