From: sashiko-bot@kernel.org
To: "Hungyu Lin" <dennylin0707@gmail.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH] tty: discard flip-buffer input for TCSAFLUSH
Date: Tue, 27 Oct 2026 05:56:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-186146@kernel.org> (raw)
In-Reply-To: <20261027054304.35543-1-dennylin0707@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] tty: missing tty_unthrottle() in set_termios() on TERMIOS_FLUSH
--
commit 757d2dda2b0d44401d4d977f6413afe8f7669c45
Author: Hungyu Lin <dennylin0707@gmail.com>
tty: discard flip-buffer input for TCSAFLUSH
This commit updates set_termios() to call tty_buffer_flush() instead of only
invoking the line discipline flush_buffer callback when TERMIOS_FLUSH is set,
so pending input in the tty flip buffers is also discarded on TCSAFLUSH.
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index 90c70d8d14e3a..45cb77185dbb2 100644
> --- a/drivers/tty/tty_ioctl.c
> +++ b/drivers/tty/tty_ioctl.c
> @@ -496,8 +496,8 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
>
> ld = tty_ldisc_ref(tty);
> if (ld != NULL) {
> - if ((opt & TERMIOS_FLUSH) && ld->ops->flush_buffer)
> - ld->ops->flush_buffer(tty);
> + if (opt & TERMIOS_FLUSH)
> + tty_buffer_flush(tty, ld);
[Severity: High]
Should this path also call tty_unthrottle(tty) after flushing the buffers,
similar to how __tty_perform_flush() handles TCIFLUSH and TCIOFLUSH?
drivers/tty/tty_ioctl.c:__tty_perform_flush() {
switch (arg) {
case TCIFLUSH:
if (ld && ld->ops->flush_buffer) {
ld->ops->flush_buffer(tty);
tty_unthrottle(tty);
}
break;
}
When a terminal using N_TTY fills ldata->read_buf and queues additional bytes
in the flip buffers, n_tty_receive_buf_common() sets ldata->no_room and calls
n_tty_check_throttle() -> tty_throttle_safe(), which sets TTY_THROTTLED and
throttles the underlying driver (or on a PTY pair, fills port->buf up to
mem_limit so the master blocks on write_wait).
Previously, set_termios() only called ld->ops->flush_buffer(tty), leaving the
flip buffer data intact to refill ldata->read_buf via flush_to_ldisc(), so a
subsequent n_tty_read() would still see input_available_p(tty, 0) and reach
n_tty_check_unthrottle(tty).
With tty_buffer_flush(tty, ld) now emptying both the flip buffers and
ldata->read_buf without calling tty_unthrottle(tty), a subsequent n_tty_read()
sees no available input and blocks in n_tty_wait_for_input() before reaching
n_tty_check_unthrottle(tty):
drivers/tty/n_tty.c:n_tty_read() {
if (!input_available_p(tty, 0)) {
up_read(&tty->termios_rwsem);
tty_buffer_flush_work(tty->port);
down_read(&tty->termios_rwsem);
if (!input_available_p(tty, 0)) {
int ret = n_tty_wait_for_input(tty, file, &wait,
&timeout);
if (ret <= 0) {
retval = ret;
break;
}
continue;
}
}
}
Can this leave a throttled serial/USB-serial device unable to receive new
input to wake the reader, or leave a PTY master permanently blocked on
write_wait after tcsetattr() with TCSAFLUSH?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261027054304.35543-1-dennylin0707@gmail.com?part=1
next prev parent reply other threads:[~2026-10-27 5:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 5:43 [PATCH] tty: discard flip-buffer input for TCSAFLUSH Hungyu Lin
2026-10-27 5:56 ` sashiko-bot [this message]
2026-10-27 6:00 ` Greg KH
2026-10-27 8:21 ` Hungyu Lin
2026-10-27 9:25 ` Greg KH
2026-10-27 16:36 ` Hungyu Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-186146@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dennylin0707@gmail.com \
--cc=linux-serial@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.