All of lore.kernel.org
 help / color / mirror / Atom feed
* [1/1] usb: chipidea: fix static checker warning for NULL pointer
@ 2018-12-24  1:18 Peter Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Chen @ 2018-12-24  1:18 UTC (permalink / raw)
  To: linux-usb; +Cc: dl-linux-imx, dan.carpenter, Peter Chen

During the static checker, "data->usbmisc_data" may be NULL.
Fix it by this pointer judgement before using.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index e81de9ca8729..9b45aa422e69 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -316,7 +316,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 	if (IS_ERR(data->usbmisc_data))
 		return PTR_ERR(data->usbmisc_data);
 
-	if (of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC) {
+	if ((of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC)
+		&& data->usbmisc_data) {
 		pdata.flags |= CI_HDRC_IMX_IS_HSIC;
 		data->usbmisc_data->hsic = 1;
 		data->pinctrl = devm_pinctrl_get(dev);

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

* [1/1] usb: chipidea: fix static checker warning for NULL pointer
@ 2019-01-18  1:35 Peter Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Chen @ 2019-01-18  1:35 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, dl-linux-imx

> 
> On Thu, Jan 17, 2019 at 09:24:20AM +0000, Peter Chen wrote:
> > During the static checker, "data->usbmisc_data" may be NULL.
> 
> I can not quite parse this sentance.  Do you mean that a static checker found this
> issue?

I think "yes", Dan Carpenter reported it.

https://www.spinics.net/lists/linux-usb/msg175431.html

> 
> > Fix it by adding this pointer judgement before using.
> >
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Signed-off-by: Peter Chen <peter.chen@nxp.com>
> > ---
> >  drivers/usb/chipidea/ci_hdrc_imx.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c
> > b/drivers/usb/chipidea/ci_hdrc_imx.c
> > index e81de9ca8729..9b45aa422e69 100644
> > --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> > +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> > @@ -316,7 +316,8 @@ static int ci_hdrc_imx_probe(struct platform_device
> *pdev)
> >  	if (IS_ERR(data->usbmisc_data))
> >  		return PTR_ERR(data->usbmisc_data);
> >
> > -	if (of_usb_get_phy_mode(dev->of_node) ==
> USBPHY_INTERFACE_MODE_HSIC) {
> > +	if ((of_usb_get_phy_mode(dev->of_node) ==
> USBPHY_INTERFACE_MODE_HSIC)
> > +		&& data->usbmisc_data) {
> 
> Are you sure that is correct?  If usbmisc_data is NULL, then you just took out a
> bunch of checking and lookups.  Don't you normally need to do this even if that
> pointer is NULL?
> 

If usbmisc_data is NULL, there is a NULL pointer deference. And if usbmisc_data
is NULL, we don't need to do rest of this if {} statement.

This can be error pointers on error or NULL if there is no misc data.

   316          if (IS_ERR(data->usbmisc_data))
   317                  return PTR_ERR(data->usbmisc_data);
   318  
   319          if (of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC) {
   320                  pdata.flags |= CI_HDRC_IMX_IS_HSIC;
   321                  data->usbmisc_data->hsic = 1;
                        ^^^^^^^^^^^^^^^^^^^^^^^^

> Will the rest of the function still work properly if that is the case?
> 

At this if {} statement, the usbmisc_data needs to be set. The rest of code in this probe can work proper
if usbmisc_data is NULL.

Peter

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

* [1/1] usb: chipidea: fix static checker warning for NULL pointer
@ 2019-01-17 10:58 Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2019-01-17 10:58 UTC (permalink / raw)
  To: Peter Chen; +Cc: linux-usb, dl-linux-imx

On Thu, Jan 17, 2019 at 09:24:20AM +0000, Peter Chen wrote:
> During the static checker, "data->usbmisc_data" may be NULL.

I can not quite parse this sentance.  Do you mean that a static checker
found this issue?

> Fix it by adding this pointer judgement before using.
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Peter Chen <peter.chen@nxp.com>
> ---
>  drivers/usb/chipidea/ci_hdrc_imx.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
> index e81de9ca8729..9b45aa422e69 100644
> --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> @@ -316,7 +316,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
>  	if (IS_ERR(data->usbmisc_data))
>  		return PTR_ERR(data->usbmisc_data);
>  
> -	if (of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC) {
> +	if ((of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC)
> +		&& data->usbmisc_data) {

Are you sure that is correct?  If usbmisc_data is NULL, then you just
took out a bunch of checking and lookups.  Don't you normally need to do
this even if that pointer is NULL?

Will the rest of the function still work properly if that is the case?

thanks,

greg k-h

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

* [1/1] usb: chipidea: fix static checker warning for NULL pointer
@ 2019-01-17  9:24 Peter Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Chen @ 2019-01-17  9:24 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, dl-linux-imx, Peter Chen

During the static checker, "data->usbmisc_data" may be NULL.
Fix it by adding this pointer judgement before using.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index e81de9ca8729..9b45aa422e69 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -316,7 +316,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 	if (IS_ERR(data->usbmisc_data))
 		return PTR_ERR(data->usbmisc_data);
 
-	if (of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC) {
+	if ((of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC)
+		&& data->usbmisc_data) {
 		pdata.flags |= CI_HDRC_IMX_IS_HSIC;
 		data->usbmisc_data->hsic = 1;
 		data->pinctrl = devm_pinctrl_get(dev);

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

end of thread, other threads:[~2019-01-18  1:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-24  1:18 [1/1] usb: chipidea: fix static checker warning for NULL pointer Peter Chen
2019-01-17  9:24 Peter Chen
2019-01-17 10:58 Greg Kroah-Hartman
2019-01-18  1:35 Peter Chen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.