tty: Simplify tty->count math in tty_reopen()
authorDmitry Safonov <dima@arista.com>
Thu, 1 Nov 2018 00:24:49 +0000 (00:24 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 23 Jan 2019 07:10:53 +0000 (08:10 +0100)
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 <jslaby@suse.com>
Link: lkml.kernel.org/r/<20180829022353.23568-2-dima@arista.com>
Suggested-by: Jiri Slaby <jslaby@suse.com>
Reviewed-by: Jiri Slaby <jslaby@suse.cz>
Tested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty_io.c

index a9030425f3ae33ab0089e54df365b3eedf3409a2..8ad070392e740171fce47cda1ae6b68a85a9113f 100644 (file)
@@ -1491,16 +1491,13 @@ static int tty_reopen(struct tty_struct *tty)
        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;
 }