提交 508ec60d 编写于 作者: L Linus Torvalds 提交者: Zheng Zengkai

tty: teach the n_tty ICANON case about the new "cookie continuations" too

stable inclusion
from stable-5.10.21
commit c7ff2d25bce3ce820ee537d07f9c73ca1ac00704
bugzilla: 50609

--------------------------------

commit d7fe75cb upstream.

The ICANON case is a bit messy, since it has to look for the line
ending, and has special code to then suppress line ending characters if
they match the __DISABLED_CHAR.  So it actually looks up the line ending
even past the point where it knows it won't copy it to the result
buffer.

That said, apart from all those odd legacy N_TTY ICANON cases, the
actual "should we continue copying" logic isn't really all that
complicated or different from the non-canon case.  In fact, the lack of
"wait for at least N characters" arguably makes the repeat case slightly
simpler.  It really just boils down to "there's more of the line to be
copied".

So add the necessarily trivial logic, and now the N_TTY case will give
long result lines even when in canon mode.
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 3bf1cb8c
...@@ -2009,21 +2009,22 @@ static bool copy_from_read_buf(struct tty_struct *tty, ...@@ -2009,21 +2009,22 @@ static bool copy_from_read_buf(struct tty_struct *tty,
* read_tail published * read_tail published
*/ */
static void canon_copy_from_read_buf(struct tty_struct *tty, static bool canon_copy_from_read_buf(struct tty_struct *tty,
unsigned char **kbp, unsigned char **kbp,
size_t *nr) size_t *nr)
{ {
struct n_tty_data *ldata = tty->disc_data; struct n_tty_data *ldata = tty->disc_data;
size_t n, size, more, c; size_t n, size, more, c;
size_t eol; size_t eol;
size_t tail; size_t tail, canon_head;
int found = 0; int found = 0;
/* N.B. avoid overrun if nr == 0 */ /* N.B. avoid overrun if nr == 0 */
if (!*nr) if (!*nr)
return; return false;
n = min(*nr + 1, smp_load_acquire(&ldata->canon_head) - ldata->read_tail); canon_head = smp_load_acquire(&ldata->canon_head);
n = min(*nr + 1, canon_head - ldata->read_tail);
tail = ldata->read_tail & (N_TTY_BUF_SIZE - 1); tail = ldata->read_tail & (N_TTY_BUF_SIZE - 1);
size = min_t(size_t, tail + n, N_TTY_BUF_SIZE); size = min_t(size_t, tail + n, N_TTY_BUF_SIZE);
...@@ -2067,7 +2068,11 @@ static void canon_copy_from_read_buf(struct tty_struct *tty, ...@@ -2067,7 +2068,11 @@ static void canon_copy_from_read_buf(struct tty_struct *tty,
else else
ldata->push = 0; ldata->push = 0;
tty_audit_push(); tty_audit_push();
return false;
} }
/* No EOL found - do a continuation retry if there is more data */
return ldata->read_tail != canon_head;
} }
/** /**
...@@ -2138,8 +2143,13 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, ...@@ -2138,8 +2143,13 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
* termios_rwsem, and can just continue to copy data. * termios_rwsem, and can just continue to copy data.
*/ */
if (*cookie) { if (*cookie) {
if (ldata->icanon && !L_EXTPROC(tty)) {
if (canon_copy_from_read_buf(tty, &kb, &nr))
return kb - kbuf;
} else {
if (copy_from_read_buf(tty, &kb, &nr)) if (copy_from_read_buf(tty, &kb, &nr))
return kb - kbuf; return kb - kbuf;
}
/* No more data - release locks and stop retries */ /* No more data - release locks and stop retries */
n_tty_kick_worker(tty); n_tty_kick_worker(tty);
...@@ -2236,7 +2246,8 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, ...@@ -2236,7 +2246,8 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
} }
if (ldata->icanon && !L_EXTPROC(tty)) { if (ldata->icanon && !L_EXTPROC(tty)) {
canon_copy_from_read_buf(tty, &kb, &nr); if (canon_copy_from_read_buf(tty, &kb, &nr))
goto more_to_be_read;
} else { } else {
/* Deal with packet mode. */ /* Deal with packet mode. */
if (packet && kb == kbuf) { if (packet && kb == kbuf) {
...@@ -2254,6 +2265,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, ...@@ -2254,6 +2265,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
* will release them when done. * will release them when done.
*/ */
if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) { if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) {
more_to_be_read:
remove_wait_queue(&tty->read_wait, &wait); remove_wait_queue(&tty->read_wait, &wait);
*cookie = cookie; *cookie = cookie;
return kb - kbuf; return kb - kbuf;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册