* [PATCH] usb: cdns3: Handle ZLP request allocation failure
@ 2026-08-17 7:59 Triet Hoang
2026-08-17 9:03 ` [PATCH v2] " Triet Hoang
0 siblings, 1 reply; 3+ messages in thread
From: Triet Hoang @ 2026-08-17 7:59 UTC (permalink / raw)
To: peter.chen; +Cc: pawell, rogerq, gregkh, linux-usb, linux-kernel, Triet Hoang
Check the return value of cdns3_gadget_ep_alloc_request() before
dereferencing the returned request.
Signed-off-by: Triet Hoang <triet.hoang.dev@gmail.com>
---
drivers/usb/cdns3/cdns3-gadget.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
index 42311c1bfada..6211e1f2c0c1 100644
--- a/drivers/usb/cdns3/cdns3-gadget.c
+++ b/drivers/usb/cdns3/cdns3-gadget.c
@@ -2662,6 +2662,11 @@ static int cdns3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
struct cdns3_request *priv_req;
zlp_request = cdns3_gadget_ep_alloc_request(ep, GFP_ATOMIC);
+ if (!zlp_request) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
zlp_request->buf = priv_dev->zlp_buf;
zlp_request->length = 0;
@@ -2673,6 +2678,7 @@ static int cdns3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
ret = __cdns3_gadget_ep_queue(ep, zlp_request, gfp_flags);
}
+out:
spin_unlock_irqrestore(&priv_dev->lock, flags);
return ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v2] usb: cdns3: Handle ZLP request allocation failure
2026-08-17 7:59 [PATCH] usb: cdns3: Handle ZLP request allocation failure Triet Hoang
@ 2026-08-17 9:03 ` Triet Hoang
2026-08-17 11:01 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Triet Hoang @ 2026-08-17 9:03 UTC (permalink / raw)
To: peter.chen; +Cc: pawell, rogerq, gregkh, linux-usb, linux-kernel, Triet Hoang
Check the return value of cdns3_gadget_ep_alloc_request() before
dereferencing the returned request.
Changes in v2:
- Allocate the ZLP request before queuing the primary request.
- Free the allocated ZLP request when the primary request queueing fails.
Signed-off-by: Triet Hoang <triet.hoang.dev@gmail.com>
---
drivers/usb/cdns3/cdns3-gadget.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
index 42311c1bfada..05d225f99012 100644
--- a/drivers/usb/cdns3/cdns3-gadget.c
+++ b/drivers/usb/cdns3/cdns3-gadget.c
@@ -2641,7 +2641,7 @@ static int __cdns3_gadget_ep_queue(struct usb_ep *ep,
static int cdns3_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 cdns3_endpoint *priv_ep;
struct cdns3_device *priv_dev;
unsigned long flags;
@@ -2655,24 +2655,36 @@ static int cdns3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
spin_lock_irqsave(&priv_dev->lock, flags);
- ret = __cdns3_gadget_ep_queue(ep, request, gfp_flags);
-
- if (ret == 0 && request->zero && request->length &&
+ if (request->zero && request->length &&
(request->length % ep->maxpacket == 0)) {
struct cdns3_request *priv_req;
zlp_request = cdns3_gadget_ep_alloc_request(ep, GFP_ATOMIC);
+ if (!zlp_request) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
zlp_request->buf = priv_dev->zlp_buf;
zlp_request->length = 0;
priv_req = to_cdns3_request(zlp_request);
priv_req->flags |= REQUEST_ZLP;
+ }
+
+ ret = __cdns3_gadget_ep_queue(ep, request, gfp_flags);
+ if (ret)
+ goto out;
+ if (zlp_request) {
dev_dbg(priv_dev->dev, "Queuing ZLP for endpoint: %s\n",
priv_ep->name);
ret = __cdns3_gadget_ep_queue(ep, zlp_request, gfp_flags);
}
+out:
+ if (ret && zlp_request)
+ cdns3_gadget_ep_free_request(ep, zlp_request);
spin_unlock_irqrestore(&priv_dev->lock, flags);
return ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] usb: cdns3: Handle ZLP request allocation failure
2026-08-17 9:03 ` [PATCH v2] " Triet Hoang
@ 2026-08-17 11:01 ` Greg KH
0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2026-08-17 11:01 UTC (permalink / raw)
To: Triet Hoang; +Cc: peter.chen, pawell, rogerq, linux-usb, linux-kernel
On Mon, Aug 17, 2026 at 04:03:20PM +0700, Triet Hoang wrote:
> Check the return value of cdns3_gadget_ep_alloc_request() before
> dereferencing the returned request.
>
> Changes in v2:
> - Allocate the ZLP request before queuing the primary request.
> - Free the allocated ZLP request when the primary request queueing fails.
The "changes" go below the --- line, right?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-17 11:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 7:59 [PATCH] usb: cdns3: Handle ZLP request allocation failure Triet Hoang
2026-08-17 9:03 ` [PATCH v2] " Triet Hoang
2026-08-17 11:01 ` Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.