netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* re: net: qmi_wwan: bind to both control and data interface
@ 2012-06-22 14:25 Dan Carpenter
  2012-06-22 16:27 ` Bjørn Mork
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2012-06-22 14:25 UTC (permalink / raw)
  To: bjorn; +Cc: netdev

Hello Bjørn Mork,

The patch 230718bda1be: "net: qmi_wwan: bind to both control and data 
interface" from Jun 19, 2012, leads to the following Smatch warning:
drivers/net/usb/qmi_wwan.c:206 qmi_wwan_bind()
	 error: potential NULL dereference 'cdc_union'.

drivers/net/usb/qmi_wwan.c
   205          /* verify CDC Union */
   206          if (desc->bInterfaceNumber != cdc_union->bMasterInterface0) {
                                              ^^^^^^^^^

cdc_union is only non-NULL for USB_CDC_UNION_TYPE.  We used to check for
NULL here but your patch removes the check.  I just want to verify that
that was intended.

   207                  dev_err(&intf->dev, "bogus CDC Union: master=%u\n", cdc_union->bMasterInterface0);
   208                  goto err;
   209          }
   210  

regards,
dan carpenter

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

* Re: net: qmi_wwan: bind to both control and data interface
  2012-06-22 14:25 net: qmi_wwan: bind to both control and data interface Dan Carpenter
@ 2012-06-22 16:27 ` Bjørn Mork
  2012-06-22 16:56   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Bjørn Mork @ 2012-06-22 16:27 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: netdev

Dan Carpenter <dan.carpenter@oracle.com> writes:

> The patch 230718bda1be: "net: qmi_wwan: bind to both control and data 
> interface" from Jun 19, 2012, leads to the following Smatch warning:
> drivers/net/usb/qmi_wwan.c:206 qmi_wwan_bind()
> 	 error: potential NULL dereference 'cdc_union'.
>
> drivers/net/usb/qmi_wwan.c
>    205          /* verify CDC Union */
>    206          if (desc->bInterfaceNumber != cdc_union->bMasterInterface0) {
>                                               ^^^^^^^^^
>
> cdc_union is only non-NULL for USB_CDC_UNION_TYPE.  We used to check for
> NULL here but your patch removes the check.  I just want to verify that
> that was intended.
>
>    207                  dev_err(&intf->dev, "bogus CDC Union: master=%u\n", cdc_union->bMasterInterface0);
>    208                  goto err;
>    209          }
>    210  

Thanks for the notification, but this was intentional while touching the
code anyway.  The test always was redundant because the parsing code
ensure that cdc_union cannot be NULL at that point.


Bjørn

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

* Re: net: qmi_wwan: bind to both control and data interface
  2012-06-22 16:27 ` Bjørn Mork
@ 2012-06-22 16:56   ` Dan Carpenter
  2012-06-22 17:34     ` Bjørn Mork
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2012-06-22 16:56 UTC (permalink / raw)
  To: Bjørn Mork; +Cc: netdev

On Fri, Jun 22, 2012 at 06:27:17PM +0200, Bjørn Mork wrote:
> Dan Carpenter <dan.carpenter@oracle.com> writes:
> 
> > The patch 230718bda1be: "net: qmi_wwan: bind to both control and data 
> > interface" from Jun 19, 2012, leads to the following Smatch warning:
> > drivers/net/usb/qmi_wwan.c:206 qmi_wwan_bind()
> > 	 error: potential NULL dereference 'cdc_union'.
> >
> > drivers/net/usb/qmi_wwan.c
> >    205          /* verify CDC Union */
> >    206          if (desc->bInterfaceNumber != cdc_union->bMasterInterface0) {
> >                                               ^^^^^^^^^
> >
> > cdc_union is only non-NULL for USB_CDC_UNION_TYPE.  We used to check for
> > NULL here but your patch removes the check.  I just want to verify that
> > that was intended.
> >
> >    207                  dev_err(&intf->dev, "bogus CDC Union: master=%u\n", cdc_union->bMasterInterface0);
> >    208                  goto err;
> >    209          }
> >    210  
> 
> Thanks for the notification, but this was intentional while touching the
> code anyway.  The test always was redundant because the parsing code
> ensure that cdc_union cannot be NULL at that point.
> 

Yeah.  I see that now.  I think it would be more readable if the
check were rewritten like this.  That way you can see immediately
that it's checking for USB_CDC_UNION_TYPE without scrolling back and
forth in the code.

diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index f1e7791..23cb13c 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -129,7 +129,6 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf)
 	struct usb_interface_descriptor *desc = &intf->cur_altsetting->desc;
 	struct usb_cdc_union_desc *cdc_union = NULL;
 	struct usb_cdc_ether_desc *cdc_ether = NULL;
-	u32 required = 1 << USB_CDC_HEADER_TYPE | 1 << USB_CDC_UNION_TYPE;
 	u32 found = 0;
 	struct usb_driver *driver = driver_of(intf);
 	struct qmi_wwan_state *info = (void *)&dev->data;
@@ -197,7 +196,8 @@ next_desc:
 	}
 
 	/* did we find all the required ones? */
-	if ((found & required) != required) {
+	if (!(found & (1 << USB_CDC_HEADER_TYPE)) ||
+	    !(found & (1 << USB_CDC_UNION_TYPE))) {
 		dev_err(&intf->dev, "CDC functional descriptors missing\n");
 		goto err;
 	}

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

* Re: net: qmi_wwan: bind to both control and data interface
  2012-06-22 16:56   ` Dan Carpenter
@ 2012-06-22 17:34     ` Bjørn Mork
  0 siblings, 0 replies; 4+ messages in thread
From: Bjørn Mork @ 2012-06-22 17:34 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: netdev

Dan Carpenter <dan.carpenter@oracle.com> writes:
> On Fri, Jun 22, 2012 at 06:27:17PM +0200, Bjørn Mork wrote:
>
>> Thanks for the notification, but this was intentional while touching the
>> code anyway.  The test always was redundant because the parsing code
>> ensure that cdc_union cannot be NULL at that point.
>> 
>
> Yeah.  I see that now.  I think it would be more readable if the
> check were rewritten like this.  That way you can see immediately
> that it's checking for USB_CDC_UNION_TYPE without scrolling back and
> forth in the code.
>
> diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
> index f1e7791..23cb13c 100644
> --- a/drivers/net/usb/qmi_wwan.c
> +++ b/drivers/net/usb/qmi_wwan.c
> @@ -129,7 +129,6 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf)
>  	struct usb_interface_descriptor *desc = &intf->cur_altsetting->desc;
>  	struct usb_cdc_union_desc *cdc_union = NULL;
>  	struct usb_cdc_ether_desc *cdc_ether = NULL;
> -	u32 required = 1 << USB_CDC_HEADER_TYPE | 1 << USB_CDC_UNION_TYPE;
>  	u32 found = 0;
>  	struct usb_driver *driver = driver_of(intf);
>  	struct qmi_wwan_state *info = (void *)&dev->data;
> @@ -197,7 +196,8 @@ next_desc:
>  	}
>  
>  	/* did we find all the required ones? */
> -	if ((found & required) != required) {
> +	if (!(found & (1 << USB_CDC_HEADER_TYPE)) ||
> +	    !(found & (1 << USB_CDC_UNION_TYPE))) {
>  		dev_err(&intf->dev, "CDC functional descriptors missing\n");
>  		goto err;
>  	}


I fully agree.  Feel free to add my

Acked-by: Bjørn Mork <bjorn@mork.no>

if you want to submit that.



Bjørn

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

end of thread, other threads:[~2012-06-22 17:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-22 14:25 net: qmi_wwan: bind to both control and data interface Dan Carpenter
2012-06-22 16:27 ` Bjørn Mork
2012-06-22 16:56   ` Dan Carpenter
2012-06-22 17:34     ` Bjørn Mork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).