From: Mehmet Fide <mehmet.fide@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Neill Kapron <nkapron@google.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Wayne Chang <waynec@nvidia.com>,
Jon Hunter <jonathanh@nvidia.com>, Felipe Balbi <balbi@ti.com>,
Felipe Balbi <balbi@kernel.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
mehmet.fide@screeningeagle.com
Subject: [PATCH v2 2/2] usb: gadget: u_serial: implement flush_buffer
Date: Mon, 19 Oct 2026 11:09:04 +0200 [thread overview]
Message-ID: <20261019090904.3264978-2-mehmet.fide@gmail.com> (raw)
In-Reply-To: <20261019085855.3259716-1-mehmet.fide@gmail.com>
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
gs_close() waits up to GS_CLOSE_TIMEOUT (15 s) for the write buffer
to drain while the gadget is connected. When the host does not read
the port, for example because no application on the host has it open,
the last close blocks for the full timeout. tcflush(TCOFLUSH) cannot
avoid that: u_serial has no flush_buffer operation, so the request is
a no-op.
Implement flush_buffer: discard the buffered output under the port
lock and wake up the close and write waiters. As on other tty drivers,
a hangup and an interrupt character (ISIG without NOFLSH) now discard
the pending output as well.
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Changes in v2:
- none, now after the patch that keeps the port alive for the hangup
drivers/usb/gadget/function/u_serial.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 19eea724280b..187a2598181a 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -822,6 +822,19 @@ static void gs_flush_chars(struct tty_struct *tty)
spin_unlock_irqrestore(&port->port_lock, flags);
}
+static void gs_flush_buffer(struct tty_struct *tty)
+{
+ struct gs_port *port = tty->driver_data;
+ unsigned long flags;
+
+ spin_lock_irqsave(&port->port_lock, flags);
+ kfifo_reset(&port->port_write_buf);
+ spin_unlock_irqrestore(&port->port_lock, flags);
+
+ wake_up_interruptible(&port->drain_wait);
+ tty_wakeup(tty);
+}
+
static unsigned int gs_write_room(struct tty_struct *tty)
{
struct gs_port *port = tty->driver_data;
@@ -946,6 +959,7 @@ static const struct tty_operations gs_tty_ops = {
.write = gs_write,
.put_char = gs_put_char,
.flush_chars = gs_flush_chars,
+ .flush_buffer = gs_flush_buffer,
.write_room = gs_write_room,
.chars_in_buffer = gs_chars_in_buffer,
.unthrottle = gs_unthrottle,
--
2.55.0
prev parent reply other threads:[~2026-10-19 9:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 8:58 [PATCH v2 0/2] usb: gadget: u_serial: flush_buffer, and keep the port for its tty Mehmet Fide
2026-10-19 9:09 ` [PATCH v2 1/2] usb: gadget: u_serial: keep the port until its tty is released Mehmet Fide
2026-10-19 9:09 ` Mehmet Fide [this message]
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=20261019090904.3264978-2-mehmet.fide@gmail.com \
--to=mehmet.fide@gmail.com \
--cc=balbi@kernel.org \
--cc=balbi@ti.com \
--cc=bigeasy@linutronix.de \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=jonathanh@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mehmet.fide@screeningeagle.com \
--cc=nkapron@google.com \
--cc=waynec@nvidia.com \
/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®