mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Hungyu Lin <dennylin0707@gmail.com>
Cc: jirislaby@kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tty: discard flip-buffer input for TCSAFLUSH
Date: Tue, 27 Oct 2026 07:00:27 +0100	[thread overview]
Message-ID: <2026102711-venture-amicably-24c7@gregkh> (raw)
In-Reply-To: <20261027054304.35543-1-dennylin0707@gmail.com>

On Tue, Oct 27, 2026 at 05:43:04AM +0000, Hungyu Lin wrote:
> set_termios() handles TERMIOS_FLUSH by clearing only the line discipline's
> input buffer. Data already committed to the tty flip buffers can be
> delivered after that flush, leaving old input readable after a successful
> tcsetattr(TCSAFLUSH).
> 
> This can be reproduced with a raw PTY: complete an 8192-byte master write,
> wait until the slave reports 4095 unread bytes, and apply TCSAFLUSH.
> The remaining 4097 bytes are still readable afterwards. Small amounts of
> pending input can also survive if they have not reached the line
> discipline yet.
> 
> Use tty_buffer_flush() with the referenced line discipline to discard both
> receive queues under the existing buffer lock. The helper checks for the
> line discipline's flush_buffer callback itself.
> 
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
>  drivers/tty/tty_ioctl.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index 90c70d8d14e3..45cb77185dbb 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);
>  			tty_ldisc_deref(ld);
>  		}
>  
> -- 
> 2.43.0
> 
> 

What commit id does this fix?  How was this tested?

thanks,

greg k-h

  reply	other threads:[~2026-10-27  6:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27  5:43 Hungyu Lin
2026-10-27  6:00 ` Greg KH [this message]
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=2026102711-venture-amicably-24c7@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=dennylin0707@gmail.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®