diff mbox series

usb: gadget: serial: fix Tx stall after buffer overflow

Message ID 87pnfi8xc2.fsf@osv.gnss.ru
State New
Headers show
Series usb: gadget: serial: fix Tx stall after buffer overflow | expand

Commit Message

Sergey Organov Jan. 17, 2020, 5:29 a.m. UTC
Symptom: application opens /dev/ttyGS0 and starts sending (writing) to
it while either USB cable is not connected, or nobody listens on the
other side of the cable. If driver circular buffer overflows before
connection is established, no data will be written to the USB layer
until/unless /dev/ttyGS0 is closed and re-opened again by the
application (the latter besides having no means of being notified about
the event of establishing of the connection.)

Fix: on open and/or connect, kick Tx to flush circular buffer data to
USB layer.

NOTE: current version of the driver leaks data from one connection to
another through its internal circular buffer. It might be a good idea
to clear the buffer on open/close/connect/disconnect, in which case
the problem this patch solves would have been fixed in a different
manner. However, not only that's a more dramatic change, but to do it
right TTY-layer buffers are to be considered as well.

Signed-off-by: Sergey Organov <sorganov@gmail.com>
---

 drivers/usb/gadget/function/u_serial.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index f986e5c..d333cda 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -563,6 +563,8 @@  static int gs_start_io(struct gs_port *port)
 
        /* unblock any pending writes into our circular buffer */
        if (started) {
+               pr_debug("gs_start_tx: ttyGS%d\n", port->port_num);
+               gs_start_tx(port);
                tty_wakeup(port->port.tty);
        } else {
                gs_free_requests(ep, head, &port->read_allocated);