Commit 436fe032 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Kleber Sacilotto de Souza

tty: Drop tty->count on tty_reopen() failure

BugLink: https://bugs.launchpad.net/bugs/1791758

In case of tty_ldisc_reinit() failure, tty->count should be decremented
back, otherwise we will never release_tty().
Tetsuo reported that it fixes noisy warnings on tty release like:
  pts pts4033: tty_release: tty->count(10529) != (#fd's(7) + #kopen's(0))

Fixes: commit 892d1fa7 ("tty: Destroy ldisc instance on hangup")

Cc: stable@vger.kernel.org # v4.6+
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.com>
Reviewed-by: default avatarJiri Slaby <jslaby@suse.cz>
Tested-by: default avatarJiri Slaby <jslaby@suse.com>
Tested-by: default avatarMark Rutland <mark.rutland@arm.com>
Tested-by: default avatarTetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Signed-off-by: default avatarDmitry Safonov <dima@arista.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit fe324167)
Signed-off-by: default avatarGuilherme G. Piccoli <gpiccoli@canonical.com>
Acked-by: default avatarStefan Bader <stefan.bader@canonical.com>
Acked-by: default avatarKleber Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 3420f402
......@@ -1474,6 +1474,7 @@ void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct *tty)
static int tty_reopen(struct tty_struct *tty)
{
struct tty_driver *driver = tty->driver;
int retval;
if (driver->type == TTY_DRIVER_TYPE_PTY &&
driver->subtype == PTY_TYPE_MASTER)
......@@ -1487,10 +1488,14 @@ static int tty_reopen(struct tty_struct *tty)
tty->count++;
if (!tty->ldisc)
return tty_ldisc_reinit(tty, tty->termios.c_line);
if (tty->ldisc)
return 0;
return 0;
retval = tty_ldisc_reinit(tty, tty->termios.c_line);
if (retval)
tty->count--;
return retval;
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment