* [PATCH] usb: cdns2: allocate the trailing ZLP before queuing data
@ 2026-09-13 12:52 Slavin Liu
2026-11-20 15:37 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Slavin Liu @ 2026-09-13 12:52 UTC (permalink / raw)
To: pawell, gregkh; +Cc: linux-usb, linux-kernel, bolin.liu
A trailing ZLP allocation currently happens after the data request
has been accepted. Allocate and check it first, before publishing the
data request. Free the unqueued ZLP if data mapping fails. The ZLP has
zero length, for which the mapping helper returns success without DMA
mapping; its enqueue has no fallible mapping step on this baseline.
Detected by static analysis and reviewed with AI-assisted source auditing.
Fixes: 3eb1f1efe204 ("usb: cdns2: Add main part of Cadence USBHS driver")
Assisted-by: LLM
Signed-off-by: Slavin Liu <bolin.liu@seu.edu.cn>
---
drivers/usb/gadget/udc/cdns2/cdns2-gadget.c | 26 ++++++++++++++-------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
index 308d3c468ab1..68fed31a85c5 100644
--- a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
+++ b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
@@ -1696,7 +1696,7 @@ static int cdns2_ep_enqueue(struct cdns2_endpoint *pep,
static int cdns2_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
gfp_t gfp_flags)
{
- struct usb_request *zlp_request;
+ struct usb_request *zlp_request = NULL;
struct cdns2_request *preq;
struct cdns2_endpoint *pep;
struct cdns2_device *pdev;
@@ -1717,21 +1717,31 @@ static int cdns2_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
spin_lock_irqsave(&pdev->lock, flags);
- preq = to_cdns2_request(request);
- ret = cdns2_ep_enqueue(pep, preq, gfp_flags);
-
- if (ret == 0 && request->zero && request->length &&
- (request->length % ep->maxpacket == 0)) {
- struct cdns2_request *preq;
-
+ if (request->zero && request->length &&
+ request->length % ep->maxpacket == 0) {
zlp_request = cdns2_gadget_ep_alloc_request(ep, GFP_ATOMIC);
+ if (!zlp_request) {
+ ret = -ENOMEM;
+ goto out_unlock;
+ }
zlp_request->buf = pdev->zlp_buf;
zlp_request->length = 0;
+ }
+
+ preq = to_cdns2_request(request);
+ ret = cdns2_ep_enqueue(pep, preq, gfp_flags);
+ if (ret) {
+ if (zlp_request)
+ cdns2_gadget_ep_free_request(ep, zlp_request);
+ goto out_unlock;
+ }
+ if (zlp_request) {
preq = to_cdns2_request(zlp_request);
ret = cdns2_ep_enqueue(pep, preq, gfp_flags);
}
+out_unlock:
spin_unlock_irqrestore(&pdev->lock, flags);
return ret;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: cdns2: allocate the trailing ZLP before queuing data
2026-09-13 12:52 [PATCH] usb: cdns2: allocate the trailing ZLP before queuing data Slavin Liu
@ 2026-11-20 15:37 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-11-20 15:37 UTC (permalink / raw)
To: Slavin Liu; +Cc: pawell, linux-usb, linux-kernel
On Sun, Sep 13, 2026 at 08:52:35PM +0800, Slavin Liu wrote:
> A trailing ZLP allocation currently happens after the data request
> has been accepted. Allocate and check it first, before publishing the
> data request. Free the unqueued ZLP if data mapping fails. The ZLP has
> zero length, for which the mapping helper returns success without DMA
> mapping; its enqueue has no fallible mapping step on this baseline.
>
> Detected by static analysis and reviewed with AI-assisted source auditing.
How was this tested?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 15:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-13 12:52 [PATCH] usb: cdns2: allocate the trailing ZLP before queuing data Slavin Liu
2026-11-20 15:37 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®