]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: gadget: f_hid: Fix zero length packet transfer
authorWilliam Wu <william.wu@rock-chips.com>
Tue, 26 Aug 2025 10:28:07 +0000 (18:28 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Nov 2025 20:34:20 +0000 (15:34 -0500)
[ Upstream commit ed6f727c575b1eb8136e744acfd5e7306c9548f6 ]

Set the hid req->zero flag of ep0/in_ep to true by default,
then the UDC drivers can transfer a zero length packet at
the end if the hid transfer with size divisible to EPs max
packet size according to the USB 2.0 spec.

Signed-off-by: William Wu <william.wu@rock-chips.com>
Link: https://lore.kernel.org/r/1756204087-26111-1-git-send-email-william.wu@rock-chips.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/gadget/function/f_hid.c

index ab4d170469f5781eba2691d9b42da83e08eedcda..34d49d96def613a0f8272700201e221ff2c31518 100644 (file)
@@ -526,7 +526,7 @@ try_again:
        }
 
        req->status   = 0;
-       req->zero     = 0;
+       req->zero     = 1;
        req->length   = count;
        req->complete = f_hidg_req_complete;
        req->context  = hidg;
@@ -982,7 +982,7 @@ stall:
        return -EOPNOTSUPP;
 
 respond:
-       req->zero = 0;
+       req->zero = 1;
        req->length = length;
        status = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
        if (status < 0)