diff mbox series

[1/3] usb: chipidea: ci_hdrc_imx: fix usbmisc handling

Message ID 20250309175805.661684-2-pchelkin@ispras.ru (mailing list archive)
State New
Headers show
Series usb: chipidea: ci_hdrc_imx: fix some issues in probe/remove | expand

Commit Message

Fedor Pchelkin March 9, 2025, 5:57 p.m. UTC
usbmisc is an optional device property so it is totally valid for the
corresponding data->usbmisc_data to have a NULL value.

Check that before dereferencing the pointer.

Found by Linux Verification Center (linuxtesting.org) with Svace static
analysis tool.

Fixes: 74adad500346 ("usb: chipidea: ci_hdrc_imx: decrement device's refcount in .remove() and in the error path of .probe()")
Cc: stable@vger.kernel.org
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Frank Li March 10, 2025, 2:50 p.m. UTC | #1
On Sun, Mar 09, 2025 at 08:57:57PM +0300, Fedor Pchelkin wrote:
> usbmisc is an optional device property so it is totally valid for the
> corresponding data->usbmisc_data to have a NULL value.
>
> Check that before dereferencing the pointer.
>
> Found by Linux Verification Center (linuxtesting.org) with Svace static
> analysis tool.

I have not seen any words "linuxtesting.org" in linux source tree. I am
not sure if it reproducable for other people. So this sense have not
provide much useful information.

Fixes itself is good.

Frank

>
> Fixes: 74adad500346 ("usb: chipidea: ci_hdrc_imx: decrement device's refcount in .remove() and in the error path of .probe()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> ---
>  drivers/usb/chipidea/ci_hdrc_imx.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
> index 1a7fc638213e..619779eef333 100644
> --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> @@ -534,7 +534,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
>  		cpu_latency_qos_remove_request(&data->pm_qos_req);
>  	data->ci_pdev = NULL;
>  err_put:
> -	put_device(data->usbmisc_data->dev);
> +	if (data->usbmisc_data)
> +		put_device(data->usbmisc_data->dev);
>  	return ret;
>  }
>
> @@ -559,7 +560,8 @@ static void ci_hdrc_imx_remove(struct platform_device *pdev)
>  		if (data->hsic_pad_regulator)
>  			regulator_disable(data->hsic_pad_regulator);
>  	}
> -	put_device(data->usbmisc_data->dev);
> +	if (data->usbmisc_data)
> +		put_device(data->usbmisc_data->dev);
>  }
>
>  static void ci_hdrc_imx_shutdown(struct platform_device *pdev)
> --
> 2.48.1
>
diff mbox series

Patch

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index 1a7fc638213e..619779eef333 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -534,7 +534,8 @@  static int ci_hdrc_imx_probe(struct platform_device *pdev)
 		cpu_latency_qos_remove_request(&data->pm_qos_req);
 	data->ci_pdev = NULL;
 err_put:
-	put_device(data->usbmisc_data->dev);
+	if (data->usbmisc_data)
+		put_device(data->usbmisc_data->dev);
 	return ret;
 }
 
@@ -559,7 +560,8 @@  static void ci_hdrc_imx_remove(struct platform_device *pdev)
 		if (data->hsic_pad_regulator)
 			regulator_disable(data->hsic_pad_regulator);
 	}
-	put_device(data->usbmisc_data->dev);
+	if (data->usbmisc_data)
+		put_device(data->usbmisc_data->dev);
 }
 
 static void ci_hdrc_imx_shutdown(struct platform_device *pdev)