[PATCH] usb: gadget: f_printer: Fix fsync waiting for active transfers

From: raoxu

Date: Mon Nov 09 2026 - 22:38:02 EST


From: Xu Rao <raoxu@xxxxxxxxxxxxx>

printer_fsync() checks the list of free TX requests before deciding
whether to wait for all data to be sent. Once a write queues a request,
it is removed from the free list and placed on tx_reqs_active, so the
free list can be empty while a USB transfer is still in progress.

This allows fsync() to return before the queued data has completed.
Check tx_reqs_active instead, matching the wait condition and the
completion callback that wakes tx_flush_wait.

Signed-off-by: Xu Rao <raoxu@xxxxxxxxxxxxx>
---
drivers/usb/gadget/function/f_printer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index 1857d786110b..a2437c8e668d 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -736,7 +736,7 @@ printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync)
return -ENODEV;
}

- tx_list_empty = (likely(list_empty(&dev->tx_reqs)));
+ tx_list_empty = (likely(list_empty(&dev->tx_reqs_active)));
spin_unlock_irqrestore(&dev->lock, flags);

if (!tx_list_empty) {
--
2.50.1