RE: [PATCH 1/1] usb: chipidea: fix static checker warning for NULL pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 
> 
> 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@xxxxxxxxxx>
> > Signed-off-by: Peter Chen <peter.chen@xxxxxxx>
> > ---
> >  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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux