Skip to content

Commit 171f90d

Browse files
0x7f454c46gregkh
authored andcommitted
tty: Drop tty->count on tty_reopen() failure
commit fe32416 upstream. 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 892d1fa ("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: Jiri Slaby <jslaby@suse.cz> Tested-by: Jiri Slaby <jslaby@suse.com> Tested-by: Mark Rutland <mark.rutland@arm.com> Tested-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> Signed-off-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c92e73b commit 171f90d

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

drivers/tty/tty_io.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ static void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct *
12541254
static int tty_reopen(struct tty_struct *tty)
12551255
{
12561256
struct tty_driver *driver = tty->driver;
1257+
int retval;
12571258

12581259
if (driver->type == TTY_DRIVER_TYPE_PTY &&
12591260
driver->subtype == PTY_TYPE_MASTER)
@@ -1267,10 +1268,14 @@ static int tty_reopen(struct tty_struct *tty)
12671268

12681269
tty->count++;
12691270

1270-
if (!tty->ldisc)
1271-
return tty_ldisc_reinit(tty, tty->termios.c_line);
1271+
if (tty->ldisc)
1272+
return 0;
12721273

1273-
return 0;
1274+
retval = tty_ldisc_reinit(tty, tty->termios.c_line);
1275+
if (retval)
1276+
tty->count--;
1277+
1278+
return retval;
12741279
}
12751280

12761281
/**

0 commit comments

Comments
 (0)