diff mbox series

usb: cdns2: fix possible null-ptr-deref in cdns2_gadget_ep_queue()

Message ID 20241028035028.2657102-1-yiyang13@huawei.com
State New
Headers show
Series usb: cdns2: fix possible null-ptr-deref in cdns2_gadget_ep_queue() | expand

Commit Message

Yi Yang Oct. 28, 2024, 3:50 a.m. UTC
The cdns2_gadget_ep_alloc_request() will return NULL when kzalloc() fails,
fix possible null-ptr-deref by check return value.

Fixes: 3eb1f1efe204 ("usb: cdns2: Add main part of Cadence USBHS driver")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 drivers/usb/gadget/udc/cdns2/cdns2-gadget.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Greg KH Oct. 29, 2024, 3:36 a.m. UTC | #1
On Mon, Oct 28, 2024 at 03:50:28AM +0000, Yi Yang wrote:
> The cdns2_gadget_ep_alloc_request() will return NULL when kzalloc() fails,
> fix possible null-ptr-deref by check return value.
> 
> Fixes: 3eb1f1efe204 ("usb: cdns2: Add main part of Cadence USBHS driver")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
>  drivers/usb/gadget/udc/cdns2/cdns2-gadget.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
> index 62fce42ef2da..c06a50af268e 100644
> --- a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
> +++ b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
> @@ -1724,6 +1724,10 @@ static int cdns2_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
>  		struct cdns2_request *preq;
>  
>  		zlp_request = cdns2_gadget_ep_alloc_request(ep, GFP_ATOMIC);
> +		if (!zlp_request) {
> +			spin_unlock_irqrestore(&pdev->lock, flags);
> +			return -ENOMEM;
> +		}
>  		zlp_request->buf = pdev->zlp_buf;
>  		zlp_request->length = 0;
>  
> -- 
> 2.25.1
> 
> 

How was this tested to verify it works properly?

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
index 62fce42ef2da..c06a50af268e 100644
--- a/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
+++ b/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
@@ -1724,6 +1724,10 @@  static int cdns2_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
 		struct cdns2_request *preq;
 
 		zlp_request = cdns2_gadget_ep_alloc_request(ep, GFP_ATOMIC);
+		if (!zlp_request) {
+			spin_unlock_irqrestore(&pdev->lock, flags);
+			return -ENOMEM;
+		}
 		zlp_request->buf = pdev->zlp_buf;
 		zlp_request->length = 0;