The driver uses the device's TX_EMPTY notification as the only gate for reusing the single bulk-out urb. That notification only tells that the device transmitter has drained; it does not guarantee that the host has retired the previous transfer, which is completed asynchronously. When a TX_EMPTY block is received while the tty layer is submitting the next transfer, the block is parsed in the bulk-in completion handler and f81534_submit_writer() submits the same urb again: URB 00000000f03a9f3b submitted while active WARNING: drivers/usb/core/urb.c:379 at usb_submit_urb ... f81534_submit_writer f81534_process_read_urb ... f81534_submit_writer f81534_write usb_submit_urb() rejects the urb with -EBUSY and the transfer buffer is rewritten while the controller may still be using it. Track whether the write urb is in flight and only reuse it after the completion handler has run. A TX_EMPTY notification received while a transfer is pending is kept and the completion handler submits the next transfer as soon as the urb is available. Fixes: 0c9bd6004d25 ("USB: serial: add Fintek F81532/534 driver") Cc: stable@vger.kernel.org Co-developed-by: Bin Yu Signed-off-by: Bin Yu Co-developed-by: Cheng Wen Signed-off-by: Cheng Wen Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> --- drivers/usb/serial/f81534.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/f81534.c b/drivers/usb/serial/f81534.c index 8fc60c4d6166..13bd29d5075b 100644 --- a/drivers/usb/serial/f81534.c +++ b/drivers/usb/serial/f81534.c @@ -159,6 +159,7 @@ struct f81534_port_private { struct work_struct lsr_work; struct usb_serial_port *port; unsigned long tx_empty; + unsigned long write_urb_active; spinlock_t msr_lock; u32 baud_base; u8 shadow_mcr; @@ -517,12 +518,22 @@ static int f81534_submit_writer(struct usb_serial_port *port, gfp_t mem_flags) if (!test_and_clear_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty)) return 0; + /* + * The TX_EMPTY token only tells that the device drained its + * transmitter; the urb may still be owned by the HCD. + */ + if (test_and_set_bit(0, &port_priv->write_urb_active)) { + set_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty); + return 0; + } + urb = port->write_urbs[0]; f81534_prepare_write_buffer(port, port->bulk_out_buffers[0]); urb->transfer_buffer_length = F81534_WRITE_BUFFER_SIZE; result = usb_submit_urb(urb, mem_flags); if (result) { + clear_bit(0, &port_priv->write_urb_active); set_bit(F81534_TX_EMPTY_BIT, &port_priv->tx_empty); dev_err(&port->dev, "%s: submit failed: %d\n", __func__, result); @@ -1270,6 +1281,9 @@ static void f81534_process_read_urb(struct urb *urb) static void f81534_write_usb_callback(struct urb *urb) { struct usb_serial_port *port = urb->context; + struct f81534_port_private *port_priv = usb_get_serial_port_data(port); + + clear_bit(0, &port_priv->write_urb_active); switch (urb->status) { case 0: @@ -1287,8 +1301,10 @@ static void f81534_write_usb_callback(struct urb *urb) default: dev_dbg(&port->dev, "%s - nonzero urb status: %d\n", __func__, urb->status); - break; + return; } + + f81534_submit_writer(port, GFP_ATOMIC); } static void f81534_lsr_worker(struct work_struct *work) -- 2.34.1