[SRU X] [PATCH 2/5] tty: Drop tty->count on tty_reopen() failure
Guilherme G. Piccoli
gpiccoli at canonical.com
Tue Jan 8 20:18:46 UTC 2019
From: Dmitry Safonov <dima at arista.com>
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 892d1fa7eaae ("tty: Destroy ldisc instance on hangup")
Cc: stable at vger.kernel.org # v4.6+
Cc: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
Cc: Jiri Slaby <jslaby at suse.com>
Reviewed-by: Jiri Slaby <jslaby at suse.cz>
Tested-by: Jiri Slaby <jslaby at suse.com>
Tested-by: Mark Rutland <mark.rutland at arm.com>
Tested-by: Tetsuo Handa <penguin-kernel at i-love.sakura.ne.jp>
Signed-off-by: Dmitry Safonov <dima at arista.com>
Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>
(cherry-picked from fe32416790093b31364c08395727de17ec96ace1 upstream)
Signed-off-by: Guilherme G. Piccoli <gpiccoli at canonical.com>
---
drivers/tty/tty_io.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 2ed3d2add7d4..d2f00378fc18 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -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;
}
/**
--
2.19.2
More information about the kernel-team
mailing list