Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] usb: chipidea: imx: check data->usbmisc_data against NULL before access
@ 2019-10-09  2:52 jun.li
  2019-10-09  8:17 ` Peter Chen
  0 siblings, 1 reply; 2+ messages in thread
From: jun.li @ 2019-10-09  2:52 UTC (permalink / raw)
  To: peter.chen; +Cc: gregkh, jun.li, linux-imx, linux-usb, dan.carpenter

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) {
-- 
2.7.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] usb: chipidea: imx: check data->usbmisc_data against NULL before access
  2019-10-09  2:52 [PATCH] usb: chipidea: imx: check data->usbmisc_data against NULL before access jun.li
@ 2019-10-09  8:17 ` Peter Chen
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Chen @ 2019-10-09  8:17 UTC (permalink / raw)
  To: Jun Li; +Cc: gregkh, dl-linux-imx, linux-usb, dan.carpenter

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.

-- 

Thanks,
Peter Chen

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09  2:52 [PATCH] usb: chipidea: imx: check data->usbmisc_data against NULL before access jun.li
2019-10-09  8:17 ` Peter Chen

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org linux-usb@archiver.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/ public-inbox