Skip to content

Commit d12ab3b

Browse files
author
CKI KWF Bot
committed
Merge: tty: n_tty: Fix buffer offsets when lookahead is used
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7626 JIRA: https://issues.redhat.com/browse/RHEL-127716 commit b19ab7e Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Date: Tue May 14 17:04:29 2024 +0300 tty: n_tty: Fix buffer offsets when lookahead is used When lookahead has "consumed" some characters (la_count > 0), n_tty_receive_buf_standard() and n_tty_receive_buf_closing() for characters beyond the la_count are given wrong cp/fp offsets which leads to duplicating and losing some characters. If la_count > 0, correct buffer pointers and make count consistent too (the latter is not strictly necessary to fix the issue but seems more logical to adjust all variables immediately to keep state consistent). Reported-by: Vadym Krevs <vkrevs@yahoo.com> Fixes: 6bb6fa6 ("tty: Implement lookahead to process XON/XOFF timely") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218834 Tested-by: Vadym Krevs <vkrevs@yahoo.com> Cc: stable@vger.kernel.org Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Link: https://lore.kernel.org/r/20240514140429.12087-1-ilpo.jarvinen@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Radostin Stoyanov <rstoyano@redhat.com> Approved-by: Waiman Long <longman@redhat.com> Approved-by: Lucas Zampieri <lzampier@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents c2332d0 + 3ddcb88 commit d12ab3b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

drivers/tty/n_tty.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,15 +1619,25 @@ static void __receive_buf(struct tty_struct *tty, const u8 *cp, const u8 *fp,
16191619
else if (ldata->raw || (L_EXTPROC(tty) && !preops))
16201620
n_tty_receive_buf_raw(tty, cp, fp, count);
16211621
else if (tty->closing && !L_EXTPROC(tty)) {
1622-
if (la_count > 0)
1622+
if (la_count > 0) {
16231623
n_tty_receive_buf_closing(tty, cp, fp, la_count, true);
1624-
if (count > la_count)
1625-
n_tty_receive_buf_closing(tty, cp, fp, count - la_count, false);
1624+
cp += la_count;
1625+
if (fp)
1626+
fp += la_count;
1627+
count -= la_count;
1628+
}
1629+
if (count > 0)
1630+
n_tty_receive_buf_closing(tty, cp, fp, count, false);
16261631
} else {
1627-
if (la_count > 0)
1632+
if (la_count > 0) {
16281633
n_tty_receive_buf_standard(tty, cp, fp, la_count, true);
1629-
if (count > la_count)
1630-
n_tty_receive_buf_standard(tty, cp, fp, count - la_count, false);
1634+
cp += la_count;
1635+
if (fp)
1636+
fp += la_count;
1637+
count -= la_count;
1638+
}
1639+
if (count > 0)
1640+
n_tty_receive_buf_standard(tty, cp, fp, count, false);
16311641

16321642
flush_echoes(tty);
16331643
if (tty->ops->flush_chars)

0 commit comments

Comments
 (0)