Re: [PATCH v3 4/6] USB: serial: add generic write control callbacks
From: Johan Hovold
Date: Thu Oct 15 2026 - 05:56:59 EST
On Tue, Aug 11, 2026 at 02:04:59PM +0800, Crescent Hsieh wrote:
> Some USB serial devices use device-specific flow control to determine
> whether write submission may proceed. The generic write path currently
> provides no way to pause submission based on driver-specific state. It
> also provides no way for a driver to restore its state if URB submission
> fails.
>
> Add an optional write_ready() callback to struct usb_serial_driver. Call
> it with port->lock held after confirming that data is queued and a write
> URB is available. If the callback returns false, stop write processing
> and leave the data in the FIFO. The driver must call
> usb_serial_generic_write_start() when writes may proceed again.
>
> Add an optional write_rollback() callback for restoring driver-specific
> state after usb_submit_urb() fails. Call it with port->lock held after
> restoring the generic transmit accounting, and pass it the length of the
> prepared transfer.
>
> Drivers which do not provide these callbacks retain the existing generic
> write behaviour.
>
> Signed-off-by: Crescent Hsieh <crescentcy.hsieh@xxxxxxxx>
> @@ -171,9 +173,7 @@ int usb_serial_generic_write_start(struct usb_serial_port *port,
> spin_unlock_irqrestore(&port->lock, flags);
>
> urb = port->write_urbs[i];
> - count = port->serial->type->prepare_write_buffer(port,
> - urb->transfer_buffer,
> - port->bulk_out_size);
> + count = type->prepare_write_buffer(port, urb->transfer_buffer, port->bulk_out_size);
I kept the last line break here to keep the line under 80 chars.
> @@ -436,4 +444,3 @@ module_exit(usb_serial_module_exit);
> usb_serial_module_driver(KBUILD_MODNAME, __serial_drivers, __ids)
>
> #endif /* __LINUX_USB_SERIAL_H */
> -
And dropped this unrelated change.
Johan