diff mbox

cxacru: ignore cx82310_eth devices

Message ID 4C82741C.2000106@simon.arlott.org.uk
State Superseded, archived
Delegated to: David Miller
Headers show

Commit Message

Simon Arlott Sept. 4, 2010, 4:30 p.m. UTC
Ignore ADSL routers, which can have the same vendor and product IDs
as ADSL modems but should be handled by the cx82310_eth driver.

This intentionally ignores device IDs that aren't currently handled
by cx82310_eth. There may be other device IDs that perhaps shouldn't
be claimed by cxacru.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
[SA: Moved to cxacru_usb_probe, message level lowered to info]
Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
---
 drivers/usb/atm/cxacru.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

Comments

Greg KH Sept. 5, 2010, 4:03 a.m. UTC | #1
On Sat, Sep 04, 2010 at 05:30:20PM +0100, Simon Arlott wrote:
> Ignore ADSL routers, which can have the same vendor and product IDs
> as ADSL modems but should be handled by the cx82310_eth driver.
> 
> This intentionally ignores device IDs that aren't currently handled
> by cx82310_eth. There may be other device IDs that perhaps shouldn't
> be claimed by cxacru.
> 
> Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> [SA: Moved to cxacru_usb_probe, message level lowered to info]
> Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
> ---
>  drivers/usb/atm/cxacru.c |   18 ++++++++++++++++--
>  1 files changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
> index 593fc5e..96fa736 100644
> --- a/drivers/usb/atm/cxacru.c
> +++ b/drivers/usb/atm/cxacru.c
> @@ -1324,8 +1324,22 @@ static struct usbatm_driver cxacru_driver = {
>  	.tx_padding	= 11,
>  };
>  
> -static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
> -{
> +static int cxacru_usb_probe(struct usb_interface *intf,
> +		const struct usb_device_id *id) {
> +	struct usb_device *usb_dev = interface_to_usbdev(intf);
> +	char buf[15];
> +
> +	/* avoid ADSL routers (cx82310_eth)
> +	 * abort if bDeviceClass is 0xff and iProduct is "USB NET CARD" */
> +	if (usb_dev->descriptor.bDeviceClass == 0xff

vendor class?  We have a macro for that?

> +			&& usb_dev->descriptor.iProduct

Almost everyone has a iProduct, right?  Why even test for that?

> +			&& usb_string(usb_dev,
> +				usb_dev->descriptor.iProduct, buf, sizeof(buf))

usb_string() should handle a 0 string, right?

> +			&& !strcmp(buf, "USB NET CARD")) {

Just to make it a bit easier to follow, how about you do the
usb_string() call in the if statment, and then compare the string and
then, if that matches you do:

> +		dev_info(&intf->dev, "ignoring cx82310_eth device\n");
> +		return -ENODEV;

Well, actually, dev_info?  I guess so, but do you really want to see
this message every time?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ondrej Zary Sept. 5, 2010, 5:01 p.m. UTC | #2
On Sunday 05 September 2010 06:03:52 Greg KH wrote:
> On Sat, Sep 04, 2010 at 05:30:20PM +0100, Simon Arlott wrote:
> > Ignore ADSL routers, which can have the same vendor and product IDs
> > as ADSL modems but should be handled by the cx82310_eth driver.
> >
> > This intentionally ignores device IDs that aren't currently handled
> > by cx82310_eth. There may be other device IDs that perhaps shouldn't
> > be claimed by cxacru.
> >
> > Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> > [SA: Moved to cxacru_usb_probe, message level lowered to info]
> > Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
> > ---
> >  drivers/usb/atm/cxacru.c |   18 ++++++++++++++++--
> >  1 files changed, 16 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
> > index 593fc5e..96fa736 100644
> > --- a/drivers/usb/atm/cxacru.c
> > +++ b/drivers/usb/atm/cxacru.c
> > @@ -1324,8 +1324,22 @@ static struct usbatm_driver cxacru_driver = {
> >  	.tx_padding	= 11,
> >  };
> >
> > -static int cxacru_usb_probe(struct usb_interface *intf, const struct
> > usb_device_id *id) -{
> > +static int cxacru_usb_probe(struct usb_interface *intf,
> > +		const struct usb_device_id *id) {
> > +	struct usb_device *usb_dev = interface_to_usbdev(intf);
> > +	char buf[15];
> > +
> > +	/* avoid ADSL routers (cx82310_eth)
> > +	 * abort if bDeviceClass is 0xff and iProduct is "USB NET CARD" */
> > +	if (usb_dev->descriptor.bDeviceClass == 0xff
>
> vendor class?  We have a macro for that?
>
> > +			&& usb_dev->descriptor.iProduct
>
> Almost everyone has a iProduct, right?  Why even test for that?
>
> > +			&& usb_string(usb_dev,
> > +				usb_dev->descriptor.iProduct, buf, sizeof(buf))
>
> usb_string() should handle a 0 string, right?
>
> > +			&& !strcmp(buf, "USB NET CARD")) {
>
> Just to make it a bit easier to follow, how about you do the
> usb_string() call in the if statment, and then compare the string and
>
> then, if that matches you do:
> > +		dev_info(&intf->dev, "ignoring cx82310_eth device\n");
> > +		return -ENODEV;

Does it look that much better?:

	if (usb_dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC
			&& usb_string(usb_dev, usb_dev->descriptor.iProduct,
				buf, sizeof(buf)) > 0)
		if (!strcmp(buf, "USB NET CARD")) {
			dev_info(&intf->dev, "ignoring cx82310_eth device\n");
			return -ENODEV;
		}

I also found a bug in my first patch - usb_string() can return negative value 
which can cause problems when not checked for.

> Well, actually, dev_info?  I guess so, but do you really want to see
> this message every time?
>
> thanks,
>
> greg k-h
Greg KH Sept. 5, 2010, 7:14 p.m. UTC | #3
On Sun, Sep 05, 2010 at 07:01:11PM +0200, Ondrej Zary wrote:
> On Sunday 05 September 2010 06:03:52 Greg KH wrote:
> > On Sat, Sep 04, 2010 at 05:30:20PM +0100, Simon Arlott wrote:
> > > Ignore ADSL routers, which can have the same vendor and product IDs
> > > as ADSL modems but should be handled by the cx82310_eth driver.
> > >
> > > This intentionally ignores device IDs that aren't currently handled
> > > by cx82310_eth. There may be other device IDs that perhaps shouldn't
> > > be claimed by cxacru.
> > >
> > > Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> > > [SA: Moved to cxacru_usb_probe, message level lowered to info]
> > > Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
> > > ---
> > >  drivers/usb/atm/cxacru.c |   18 ++++++++++++++++--
> > >  1 files changed, 16 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
> > > index 593fc5e..96fa736 100644
> > > --- a/drivers/usb/atm/cxacru.c
> > > +++ b/drivers/usb/atm/cxacru.c
> > > @@ -1324,8 +1324,22 @@ static struct usbatm_driver cxacru_driver = {
> > >  	.tx_padding	= 11,
> > >  };
> > >
> > > -static int cxacru_usb_probe(struct usb_interface *intf, const struct
> > > usb_device_id *id) -{
> > > +static int cxacru_usb_probe(struct usb_interface *intf,
> > > +		const struct usb_device_id *id) {
> > > +	struct usb_device *usb_dev = interface_to_usbdev(intf);
> > > +	char buf[15];
> > > +
> > > +	/* avoid ADSL routers (cx82310_eth)
> > > +	 * abort if bDeviceClass is 0xff and iProduct is "USB NET CARD" */
> > > +	if (usb_dev->descriptor.bDeviceClass == 0xff
> >
> > vendor class?  We have a macro for that?
> >
> > > +			&& usb_dev->descriptor.iProduct
> >
> > Almost everyone has a iProduct, right?  Why even test for that?
> >
> > > +			&& usb_string(usb_dev,
> > > +				usb_dev->descriptor.iProduct, buf, sizeof(buf))
> >
> > usb_string() should handle a 0 string, right?
> >
> > > +			&& !strcmp(buf, "USB NET CARD")) {
> >
> > Just to make it a bit easier to follow, how about you do the
> > usb_string() call in the if statment, and then compare the string and
> >
> > then, if that matches you do:
> > > +		dev_info(&intf->dev, "ignoring cx82310_eth device\n");
> > > +		return -ENODEV;
> 
> Does it look that much better?:
> 
> 	if (usb_dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC
> 			&& usb_string(usb_dev, usb_dev->descriptor.iProduct,
> 				buf, sizeof(buf)) > 0)
> 		if (!strcmp(buf, "USB NET CARD")) {
> 			dev_info(&intf->dev, "ignoring cx82310_eth device\n");
> 			return -ENODEV;
> 		}

Yes, don't you think so?

> I also found a bug in my first patch - usb_string() can return negative value 
> which can cause problems when not checked for.

Ah, nice catch.  Care to resend it now?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index 593fc5e..96fa736 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -1324,8 +1324,22 @@  static struct usbatm_driver cxacru_driver = {
 	.tx_padding	= 11,
 };
 
-static int cxacru_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
-{
+static int cxacru_usb_probe(struct usb_interface *intf,
+		const struct usb_device_id *id) {
+	struct usb_device *usb_dev = interface_to_usbdev(intf);
+	char buf[15];
+
+	/* avoid ADSL routers (cx82310_eth)
+	 * abort if bDeviceClass is 0xff and iProduct is "USB NET CARD" */
+	if (usb_dev->descriptor.bDeviceClass == 0xff
+			&& usb_dev->descriptor.iProduct
+			&& usb_string(usb_dev,
+				usb_dev->descriptor.iProduct, buf, sizeof(buf))
+			&& !strcmp(buf, "USB NET CARD")) {
+		dev_info(&intf->dev, "ignoring cx82310_eth device\n");
+		return -ENODEV;
+	}
+
 	return usbatm_usb_probe(intf, id, &cxacru_driver);
 }