diff mbox

usb: gadget: dwc2: fix memory leak in gadget_init()

Message ID 446e4dd2ab44f91ef1899240c9e3b6aed3cff6c5.1527171716.git.tovmasya@synopsys.com (mailing list archive)
State New, archived
Headers show

Commit Message

Grigor Tovmasyan May 24, 2018, 2:22 p.m. UTC
Freed allocated request for ep0 to prevent memory leak in case when
dwc2_driver_probe() failed.

Signed-off-by: Grigor Tovmasyan <tovmasya@synopsys.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
---
 drivers/usb/dwc2/gadget.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Grigor Tovmasyan May 24, 2018, 2:25 p.m. UTC | #1
Hi Stefan, Marek

Please test this patch and tell if it will cause any problem.

Thanks,
Grigor

On 5/24/2018 6:22 PM, Grigor Tovmasyan wrote:
> Freed allocated request for ep0 to prevent memory leak in case when
> dwc2_driver_probe() failed.
> 
> Signed-off-by: Grigor Tovmasyan <tovmasya@synopsys.com>
> Cc: Stefan Wahren <stefan.wahren@i2se.com>
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
>   drivers/usb/dwc2/gadget.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index f0d9ccf1d665..7ccf56da1e50 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -4739,9 +4739,11 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
>   	}
>   
>   	ret = usb_add_gadget_udc(dev, &hsotg->gadget);
> -	if (ret)
> +	if (ret) {
> +		dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep,
> +					   hsotg->ctrl_req);
>   		return ret;
> -
> +	}
>   	dwc2_hsotg_dump(hsotg);
>   
>   	return 0;
> @@ -4755,6 +4757,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
>   int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg)
>   {
>   	usb_del_gadget_udc(&hsotg->gadget);
> +	dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, hsotg->ctrl_req);
>   
>   	return 0;
>   }
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marek Szyprowski May 25, 2018, 5:13 a.m. UTC | #2
Hi Grigor,

On 2018-05-24 16:22, Grigor Tovmasyan wrote:
> Freed allocated request for ep0 to prevent memory leak in case when
> dwc2_driver_probe() failed.
>
> Signed-off-by: Grigor Tovmasyan <tovmasya@synopsys.com>
> Cc: Stefan Wahren <stefan.wahren@i2se.com>
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>

Works fine on my Exynos SoC based test boards.

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
>   drivers/usb/dwc2/gadget.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index f0d9ccf1d665..7ccf56da1e50 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -4739,9 +4739,11 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
>   	}
>   
>   	ret = usb_add_gadget_udc(dev, &hsotg->gadget);
> -	if (ret)
> +	if (ret) {
> +		dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep,
> +					   hsotg->ctrl_req);
>   		return ret;
> -
> +	}
>   	dwc2_hsotg_dump(hsotg);
>   
>   	return 0;
> @@ -4755,6 +4757,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
>   int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg)
>   {
>   	usb_del_gadget_udc(&hsotg->gadget);
> +	dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, hsotg->ctrl_req);
>   
>   	return 0;
>   }

Best regards
Stefan Wahren May 25, 2018, 6:13 a.m. UTC | #3
Hi Grigor,

> Grigor Tovmasyan <Grigor.Tovmasyan@synopsys.com> hat am 24. Mai 2018 um 16:22 geschrieben:
> 
> 
> Freed allocated request for ep0 to prevent memory leak in case when
> dwc2_driver_probe() failed.
> 
> Signed-off-by: Grigor Tovmasyan <tovmasya@synopsys.com>
> Cc: Stefan Wahren <stefan.wahren@i2se.com>
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>

currently i don't much time, but at least my tests with Raspberry Pi Zero W were successful.

Tested-by: Stefan Wahren <stefan.wahren@i2se.com>

It would be nice if you can setup some real testing devices at Synopsys in order to identify such regressions faster. kernelci.org only tests the host role of the Raspberry Pi.

Thanks
Stefan

> ---
>  drivers/usb/dwc2/gadget.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index f0d9ccf1d665..7ccf56da1e50 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -4739,9 +4739,11 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
>  	}
>  
>  	ret = usb_add_gadget_udc(dev, &hsotg->gadget);
> -	if (ret)
> +	if (ret) {
> +		dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep,
> +					   hsotg->ctrl_req);
>  		return ret;
> -
> +	}
>  	dwc2_hsotg_dump(hsotg);
>  
>  	return 0;
> @@ -4755,6 +4757,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
>  int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg)
>  {
>  	usb_del_gadget_udc(&hsotg->gadget);
> +	dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, hsotg->ctrl_req);
>  
>  	return 0;
>  }
> -- 
> 2.11.0
>
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Minas Harutyunyan May 25, 2018, 9:14 a.m. UTC | #4
Acked-by: Minas Harutyunyan <hminas@synopsys.com>

On 5/24/2018 6:22 PM, Grigor Tovmasyan wrote:
> Freed allocated request for ep0 to prevent memory leak in case when
> dwc2_driver_probe() failed.
> 
> Signed-off-by: Grigor Tovmasyan <tovmasya@synopsys.com>
> Cc: Stefan Wahren <stefan.wahren@i2se.com>
> Cc: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
>   drivers/usb/dwc2/gadget.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index f0d9ccf1d665..7ccf56da1e50 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -4739,9 +4739,11 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
>   	}
>   
>   	ret = usb_add_gadget_udc(dev, &hsotg->gadget);
> -	if (ret)
> +	if (ret) {
> +		dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep,
> +					   hsotg->ctrl_req);
>   		return ret;
> -
> +	}
>   	dwc2_hsotg_dump(hsotg);
>   
>   	return 0;
> @@ -4755,6 +4757,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
>   int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg)
>   {
>   	usb_del_gadget_udc(&hsotg->gadget);
> +	dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, hsotg->ctrl_req);
>   
>   	return 0;
>   }
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index f0d9ccf1d665..7ccf56da1e50 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4739,9 +4739,11 @@  int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
 	}
 
 	ret = usb_add_gadget_udc(dev, &hsotg->gadget);
-	if (ret)
+	if (ret) {
+		dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep,
+					   hsotg->ctrl_req);
 		return ret;
-
+	}
 	dwc2_hsotg_dump(hsotg);
 
 	return 0;
@@ -4755,6 +4757,7 @@  int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
 int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg)
 {
 	usb_del_gadget_udc(&hsotg->gadget);
+	dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, hsotg->ctrl_req);
 
 	return 0;
 }