Commit 7c61c3d8f44d5d822f758754287af644307b4af9

Authored by Peter Hurley
Committed by Greg Kroah-Hartman
1 parent ef223fb3d1

tty: Fix transient pty write() EIO

Commit 699390354da6c258b65bf8fa79cfd5feaede50b6
('pty: Ignore slave pty close() if never successfully opened')
introduced a bug with ptys whereby a write() in parallel with an
open() on an existing pty could mistakenly indicate an I/O error.

Only indicate an I/O error if the condition on open() actually exists.

Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Tested-by: Mikael Pettersson <mikpe@it.uu.se>
Cc: stable <stable@vger.kernel.org> # 3.9
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 5 additions and 8 deletions Side-by-side Diff

... ... @@ -244,14 +244,9 @@
244 244  
245 245 static int pty_open(struct tty_struct *tty, struct file *filp)
246 246 {
247   - int retval = -ENODEV;
248   -
249 247 if (!tty || !tty->link)
250   - goto out;
  248 + return -ENODEV;
251 249  
252   - set_bit(TTY_IO_ERROR, &tty->flags);
253   -
254   - retval = -EIO;
255 250 if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
256 251 goto out;
257 252 if (test_bit(TTY_PTY_LOCK, &tty->link->flags))
258 253  
... ... @@ -262,9 +257,11 @@
262 257 clear_bit(TTY_IO_ERROR, &tty->flags);
263 258 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags);
264 259 set_bit(TTY_THROTTLED, &tty->flags);
265   - retval = 0;
  260 + return 0;
  261 +
266 262 out:
267   - return retval;
  263 + set_bit(TTY_IO_ERROR, &tty->flags);
  264 + return -EIO;
268 265 }
269 266  
270 267 static void pty_set_termios(struct tty_struct *tty,