n_tty: Fix EOF push handling
authorPeter Hurley <peter@hurleysoftware.com>
Sat, 15 Jun 2013 14:21:17 +0000 (10:21 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 Jul 2013 00:08:40 +0000 (17:08 -0700)
commit40d5e0905a03601d40cd4e46b8690093c2355d03
tree6562e24794811eb13d986e4ea90a55c82cbdae26
parent9dfd16ddea9bdbc8343340e543732db0a467ae32
n_tty: Fix EOF push handling

In canonical mode, an EOF which is not the first character of the line
causes read() to complete and return the number of characters read so
far (commonly referred to as EOF push). However, if the previous read()
returned because the user buffer was full _and_ the next character
is an EOF not at the beginning of the line, read() must not return 0,
thus mistakenly indicating the end-of-file condition.

The TTY_PUSH flag is used to indicate an EOF was received which is not
at the beginning of the line. Because the EOF push condition is
evaluated by a thread other than the read(), multiple EOF pushes can
cause a premature end-of-file to be indicated.

Instead, discover the 'EOF push as first read character' condition
from the read() thread itself, and restart the i/o loop if detected.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/n_tty.c
drivers/tty/tty_io.c
include/linux/tty.h