aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/class/cdc-acm.c
diff options
context:
space:
mode:
authorSimon Arlott <simon@octiron.net>2023-08-20 20:13:01 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-08-22 14:46:11 +0200
commit09867af36969067d89c96ab1452656977f30e22a (patch)
treecabeda0f16da38deac88780bd560f02259f0bbb5 /drivers/usb/class/cdc-acm.c
parent4b3cd783808bb327d931bbb1324d6c367443b721 (diff)
downloadlinux-09867af36969067d89c96ab1452656977f30e22a.tar.gz
USB: cdc-acm: support flushing write buffers (TCOFLUSH)
If the serial device never reads data written to it (because it is "output only") then the write buffers will still be waiting for the URB to complete on close(), which will hang for 30s until the closing_wait timeout expires. This can happen with the ESP32-H2/ESP32-C6 USB serial interface. Changing the port closing_wait timeout is a privileged operation but flushing the output buffer is not a privileged operation. Implement the flush_buffer tty operation to cancel in-progress writes so that tcflush(fd, TCOFLUSH) can be used to unblock the serial port before close. Signed-off-by: Simon Arlott <simon@octiron.net> Link: https://lore.kernel.org/r/555fbc4c-043b-8932-fb9b-a208d61ffbe4@0882a8b5-c6c3-11e9-b005-00805fc181fe.uuid.home.arpa Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/class/cdc-acm.c')
-rw-r--r--drivers/usb/class/cdc-acm.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index dfb28c7c30693f..a1933a86aee04d 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -864,6 +864,19 @@ static unsigned int acm_tty_write_room(struct tty_struct *tty)
return acm_wb_is_avail(acm) ? acm->writesize : 0;
}
+static void acm_tty_flush_buffer(struct tty_struct *tty)
+{
+ struct acm *acm = tty->driver_data;
+ unsigned long flags;
+ int i;
+
+ spin_lock_irqsave(&acm->write_lock, flags);
+ for (i = 0; i < ACM_NW; i++)
+ if (acm->wb[i].use)
+ usb_unlink_urb(acm->wb[i].urb);
+ spin_unlock_irqrestore(&acm->write_lock, flags);
+}
+
static unsigned int acm_tty_chars_in_buffer(struct tty_struct *tty)
{
struct acm *acm = tty->driver_data;
@@ -2027,6 +2040,7 @@ static const struct tty_operations acm_ops = {
.hangup = acm_tty_hangup,
.write = acm_tty_write,
.write_room = acm_tty_write_room,
+ .flush_buffer = acm_tty_flush_buffer,
.ioctl = acm_tty_ioctl,
.throttle = acm_tty_throttle,
.unthrottle = acm_tty_unthrottle,