4.14-stable review patch. If anyone has any objections, please let me know.
------------------ From: Dmitry Safonov <[email protected]> commit cf62a1a13749db0d32b5cdd800ea91a4087319de upstream. As notted by Jiri, tty_ldisc_reinit() shouldn't rely on tty counter. Simplify math by increasing the counter after reinit success. Cc: Jiri Slaby <[email protected]> Link: lkml.kernel.org/r/<[email protected]> Suggested-by: Jiri Slaby <[email protected]> Reviewed-by: Jiri Slaby <[email protected]> Tested-by: Mark Rutland <[email protected]> Signed-off-by: Dmitry Safonov <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> --- drivers/tty/tty_io.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1270,16 +1270,13 @@ static int tty_reopen(struct tty_struct if (retval) return retval; - tty->count++; - if (tty->ldisc) - goto out_unlock; + if (!tty->ldisc) + retval = tty_ldisc_reinit(tty, tty->termios.c_line); + tty_ldisc_unlock(tty); - retval = tty_ldisc_reinit(tty, tty->termios.c_line); - if (retval) - tty->count--; + if (retval == 0) + tty->count++; -out_unlock: - tty_ldisc_unlock(tty); return retval; }

