tty: Check tty->count instead of TTY_CLOSING in tty_reopen()
authorPeter Hurley <peter@hurleysoftware.com>
Wed, 5 Nov 2014 17:12:48 +0000 (12:12 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 6 Nov 2014 02:24:10 +0000 (18:24 -0800)
Although perhaps not obvious, the TTY_CLOSING bit is set when the
tty count has been decremented to 0 (which occurs while holding
tty_lock). The only other case when tty count is 0 during a re-open
is when a legacy BSD pty master has been opened in parallel but
after the pty slave, which is unsupported and returns an error.

Thus !tty->count contains the complete set of degenerate conditions
under which a tty open fails.

Reviewed-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty_io.c

index 168382baf3702539630dce319d80d45e997087d4..0eaf632ad39eed7c0747d75bf6b93c7eab8e9dfc 100644 (file)
@@ -1452,7 +1452,7 @@ static int tty_reopen(struct tty_struct *tty)
 {
        struct tty_driver *driver = tty->driver;
 
-       if (test_bit(TTY_CLOSING, &tty->flags))
+       if (!tty->count)
                return -EIO;
 
        if (driver->type == TTY_DRIVER_TYPE_PTY &&