diff mbox series

[2/2] usb: dwc3: st: Add of_dev_put() in probe function

Message ID 20190819072436.31402-2-nishkadg.linux@gmail.com (mailing list archive)
State Mainlined
Commit bceb418b65b917af6d36a92ea1eaca54cafc1c2e
Headers show
Series [1/2] usb: dwc3: st: Add of_node_put() before return in probe function | expand

Commit Message

Nishka Dasgupta Aug. 19, 2019, 7:24 a.m. UTC
In function st_dwc3_probe, variable child_pdev takes the value returned
by of_find_device_by_node, which gets a device pointer but does not put
it. If child_pdev is not put before the probe function returns, it may
cause a reference leak. Hence put child_pdev after its last usage.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
---
 drivers/usb/dwc3/dwc3-st.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Patrice CHOTARD Aug. 26, 2019, 7:47 a.m. UTC | #1
On 8/19/19 9:24 AM, Nishka Dasgupta wrote:
> In function st_dwc3_probe, variable child_pdev takes the value returned
> by of_find_device_by_node, which gets a device pointer but does not put
> it. If child_pdev is not put before the probe function returns, it may
> cause a reference leak. Hence put child_pdev after its last usage.
> Issue found with Coccinelle.
>
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
>  drivers/usb/dwc3/dwc3-st.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c
> index 6f52c749cd58..c682420f25ca 100644
> --- a/drivers/usb/dwc3/dwc3-st.c
> +++ b/drivers/usb/dwc3/dwc3-st.c
> @@ -274,6 +274,7 @@ static int st_dwc3_probe(struct platform_device *pdev)
>  
>  	dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev);
>  	of_node_put(child);
> +	of_dev_put(child_pdev);
>  
>  	/*
>  	 * Configure the USB port as device or host according to the static

Reviewed-by: Patrice Chotard <patrice.chotard@st.com>

Thanks
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c
index 6f52c749cd58..c682420f25ca 100644
--- a/drivers/usb/dwc3/dwc3-st.c
+++ b/drivers/usb/dwc3/dwc3-st.c
@@ -274,6 +274,7 @@  static int st_dwc3_probe(struct platform_device *pdev)
 
 	dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev);
 	of_node_put(child);
+	of_dev_put(child_pdev);
 
 	/*
 	 * Configure the USB port as device or host according to the static