[PATCH 4/4] usb: usbtmc: send a ZLP after a full last packet in packet I/O mode

From: Nicolai Buchwitz

Date: Tue Oct 20 2026 - 11:07:55 EST


The Rigol DP800 waits for a short packet before it handles a command.
A message that ends exactly on a 64-byte boundary is never processed.
The read times out, and once the next message gets appended the device
shows "command incorrect".

Send a zero-length packet after a full last packet in usbtmc_write()
on quirked devices.

Tested on a DP832A, a DS1054Z and an SDM4065A-SC.

Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Nicolai Buchwitz <nb@xxxxxxxxxxx>
---
drivers/usb/class/usbtmc.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 861913b9de918..101d4f9fff6b5 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -1259,6 +1259,8 @@ static ssize_t usbtmc_generic_write(struct usbtmc_file_data *file_data,
usb_sndbulkpipe(data->usb_dev, data->bulk_out),
urb->transfer_buffer, aligned,
usbtmc_write_bulk_cb, file_data);
+ if (packet_mode && this_part == remaining)
+ urb->transfer_flags |= URB_ZERO_PACKET;

usb_anchor_urb(urb, &file_data->submitted);
retval = usb_submit_urb(urb, GFP_KERNEL);
@@ -1666,6 +1668,9 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
usb_sndbulkpipe(data->usb_dev, data->bulk_out),
urb->transfer_buffer, aligned,
usbtmc_write_bulk_cb, file_data);
+ /* Some devices only end a transfer on a short packet */
+ if (data->packet_io && transfersize == remaining)
+ urb->transfer_flags |= URB_ZERO_PACKET;

usb_anchor_urb(urb, &file_data->submitted);
retval = usb_submit_urb(urb, GFP_KERNEL);

--
2.53.0