diff mbox series

usb: chipidea: imx: check data->usbmisc_data against NULL before access

Message ID 20191009025228.16595-1-jun.li@nxp.com (mailing list archive)
State Mainlined
Commit df17aa9fb31f6a41aad37b984909d8ef1a958271
Headers show
Series usb: chipidea: imx: check data->usbmisc_data against NULL before access | expand

Commit Message

Jun Li Oct. 9, 2019, 2:52 a.m. UTC
From: Li Jun <jun.li@nxp.com>

As usbmisc_data is optional, so add the check before access its member,
this fix below static checker warning:
drivers/usb/chipidea/ci_hdrc_imx.c:438 ci_hdrc_imx_probe()
warn: 'data->usbmisc_data' can also be NULL
which is introduced by Patch 15b80f7c3a7f:
"usb: chipidea: imx: enable vbus and id wakeup only for OTG events"

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Comments

Peter Chen Oct. 9, 2019, 8:17 a.m. UTC | #1
On 19-10-09 10:52:28, jun.li@nxp.com wrote:
> From: Li Jun <jun.li@nxp.com>
> 
> As usbmisc_data is optional, so add the check before access its member,
> this fix below static checker warning:
> drivers/usb/chipidea/ci_hdrc_imx.c:438 ci_hdrc_imx_probe()
> warn: 'data->usbmisc_data' can also be NULL
> which is introduced by Patch 15b80f7c3a7f:
> "usb: chipidea: imx: enable vbus and id wakeup only for OTG events"
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Li Jun <jun.li@nxp.com>
> ---
>  drivers/usb/chipidea/ci_hdrc_imx.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
> index b11d70f..0498210 100644
> --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> @@ -433,13 +433,15 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
>  		goto err_clk;
>  	}
>  
> -	if (!IS_ERR(pdata.id_extcon.edev) ||
> -	    of_property_read_bool(np, "usb-role-switch"))
> -		data->usbmisc_data->ext_id = 1;
> -
> -	if (!IS_ERR(pdata.vbus_extcon.edev) ||
> -	    of_property_read_bool(np, "usb-role-switch"))
> -		data->usbmisc_data->ext_vbus = 1;
> +	if (data->usbmisc_data) {
> +		if (!IS_ERR(pdata.id_extcon.edev) ||
> +		    of_property_read_bool(np, "usb-role-switch"))
> +			data->usbmisc_data->ext_id = 1;
> +
> +		if (!IS_ERR(pdata.vbus_extcon.edev) ||
> +		    of_property_read_bool(np, "usb-role-switch"))
> +			data->usbmisc_data->ext_vbus = 1;
> +	}
>  
>  	ret = imx_usbmisc_init_post(data->usbmisc_data);
>  	if (ret) {

Applied, thanks.
diff mbox series

Patch

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index b11d70f..0498210 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -433,13 +433,15 @@  static int ci_hdrc_imx_probe(struct platform_device *pdev)
 		goto err_clk;
 	}
 
-	if (!IS_ERR(pdata.id_extcon.edev) ||
-	    of_property_read_bool(np, "usb-role-switch"))
-		data->usbmisc_data->ext_id = 1;
-
-	if (!IS_ERR(pdata.vbus_extcon.edev) ||
-	    of_property_read_bool(np, "usb-role-switch"))
-		data->usbmisc_data->ext_vbus = 1;
+	if (data->usbmisc_data) {
+		if (!IS_ERR(pdata.id_extcon.edev) ||
+		    of_property_read_bool(np, "usb-role-switch"))
+			data->usbmisc_data->ext_id = 1;
+
+		if (!IS_ERR(pdata.vbus_extcon.edev) ||
+		    of_property_read_bool(np, "usb-role-switch"))
+			data->usbmisc_data->ext_vbus = 1;
+	}
 
 	ret = imx_usbmisc_init_post(data->usbmisc_data);
 	if (ret) {