Module Name:    src
Committed By:   martin
Date:           Sun Jun  7 17:03:11 UTC 2020

Modified Files:
        src/sys/dev/usb [netbsd-9]: u3g.c ugensa.c

Log Message:
Pull up following revision(s) (requested by skrll in ticket #948):

        sys/dev/usb/ugensa.c: revision 1.42
        sys/dev/usb/u3g.c: revision 1.41

Remove duplicated USB_VENDOR_SIERRA USB_PRODUCT_SIERRA_USB305 entry
PR kern/55329

Replace calls to usbd_device2interface_handle in u3g_match() and
u3g_attach() with the interface already passed in uiaa->uiaa_iface and
store the interface in sc->sc_iface for later use by u3g_open()/

Also skip Direct IP interfaces in u3g_match() to avoid potential side
effects.

PR kern/55330


To generate a diff of this commit:
cvs rdiff -u -r1.37.2.1 -r1.37.2.2 src/sys/dev/usb/u3g.c
cvs rdiff -u -r1.39 -r1.39.2.1 src/sys/dev/usb/ugensa.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/u3g.c
diff -u src/sys/dev/usb/u3g.c:1.37.2.1 src/sys/dev/usb/u3g.c:1.37.2.2
--- src/sys/dev/usb/u3g.c:1.37.2.1	Thu Feb 27 17:22:56 2020
+++ src/sys/dev/usb/u3g.c	Sun Jun  7 17:03:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: u3g.c,v 1.37.2.1 2020/02/27 17:22:56 martin Exp $	*/
+/*	$NetBSD: u3g.c,v 1.37.2.2 2020/06/07 17:03:11 martin Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: u3g.c,v 1.37.2.1 2020/02/27 17:22:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: u3g.c,v 1.37.2.2 2020/06/07 17:03:11 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -114,6 +114,7 @@ struct u3g_softc {
 	struct usbd_device *	sc_udev;
 	bool			sc_dying;	/* We're going away */
 	int			sc_ifaceno;	/* Device interface number */
+	struct usbd_interface	*sc_iface;	/* Device interface */
 
 	struct u3g_com {
 		device_t	c_dev;		/* Child ucom(4) handle */
@@ -271,21 +272,12 @@ static int
 u3g_match(device_t parent, cfdata_t match, void *aux)
 {
 	struct usbif_attach_arg *uiaa = aux;
-	struct usbd_interface *iface;
+	struct usbd_interface *iface = uiaa->uiaa_iface;
 	usb_interface_descriptor_t *id;
-	usbd_status error;
 
 	if (!usb_lookup(u3g_devs, uiaa->uiaa_vendor, uiaa->uiaa_product))
 		return UMATCH_NONE;
 
-	error = usbd_device2interface_handle(uiaa->uiaa_device,
-	    uiaa->uiaa_ifaceno, &iface);
-	if (error) {
-		printf("u3g_match: failed to get interface, err=%s\n",
-		    usbd_errstr(error));
-		return UMATCH_NONE;
-	}
-
 	id = usbd_get_interface_descriptor(iface);
 	if (id == NULL) {
 		printf("u3g_match: failed to get interface descriptor\n");
@@ -302,6 +294,16 @@ u3g_match(device_t parent, cfdata_t matc
 		return UMATCH_NONE;
 
 	/*
+	 * Sierra Wireless modems use the vendor-specific class also for
+	 * Direct IP or QMI interfaces, which we should avoid attaching to.
+	 */
+	if (uiaa->uiaa_vendor == USB_VENDOR_SIERRA &&
+	    id->bInterfaceClass == UICLASS_VENDOR &&
+	    uiaa->uiaa_product == USB_PRODUCT_SIERRA_USB305 &&
+	     uiaa->uiaa_ifaceno >= 7)
+		return UMATCH_NONE;
+
+	/*
 	 * 3G modems generally report vendor-specific class
 	 *
 	 * XXX: this may be too generalised.
@@ -316,7 +318,7 @@ u3g_attach(device_t parent, device_t sel
 	struct u3g_softc *sc = device_private(self);
 	struct usbif_attach_arg *uiaa = aux;
 	struct usbd_device *dev = uiaa->uiaa_device;
-	struct usbd_interface *iface;
+	struct usbd_interface *iface = uiaa->uiaa_iface;
 	usb_interface_descriptor_t *id;
 	usb_endpoint_descriptor_t *ed;
 	struct ucom_attach_args ucaa;
@@ -330,13 +332,6 @@ u3g_attach(device_t parent, device_t sel
 	sc->sc_dying = false;
 	sc->sc_udev = dev;
 
-	error = usbd_device2interface_handle(dev, uiaa->uiaa_ifaceno, &iface);
-	if (error) {
-		aprint_error_dev(self, "failed to get interface, err=%s\n",
-		    usbd_errstr(error));
-		return;
-	}
-
 	id = usbd_get_interface_descriptor(iface);
 
 	ucaa.ucaa_info = "3G Modem";
@@ -352,6 +347,7 @@ u3g_attach(device_t parent, device_t sel
 	ucaa.ucaa_bulkin = ucaa.ucaa_bulkout = -1;
 
 	sc->sc_ifaceno = uiaa->uiaa_ifaceno;
+	sc->sc_iface = uiaa->uiaa_iface;
 	intr_address = -1;
 	intr_size = 0;
 
@@ -578,7 +574,6 @@ u3g_open(void *arg, int portno)
 	usb_device_request_t req;
 	usb_endpoint_descriptor_t *ed;
 	usb_interface_descriptor_t *id;
-	struct usbd_interface *ih;
 	usbd_status err;
 	struct u3g_com *com = &sc->sc_com[portno];
 	int i, nin;
@@ -586,14 +581,10 @@ u3g_open(void *arg, int portno)
 	if (sc->sc_dying)
  		return EIO;
 
-	err = usbd_device2interface_handle(sc->sc_udev, sc->sc_ifaceno, &ih);
-	if (err)
-		return EIO;
-
-	id = usbd_get_interface_descriptor(ih);
+	id = usbd_get_interface_descriptor(sc->sc_iface);
 
 	for (nin = i = 0; i < id->bNumEndpoints; i++) {
-		ed = usbd_interface2endpoint_descriptor(ih, i);
+		ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
 		if (ed == NULL)
 			return EIO;
 

Index: src/sys/dev/usb/ugensa.c
diff -u src/sys/dev/usb/ugensa.c:1.39 src/sys/dev/usb/ugensa.c:1.39.2.1
--- src/sys/dev/usb/ugensa.c:1.39	Thu May  9 02:43:35 2019
+++ src/sys/dev/usb/ugensa.c	Sun Jun  7 17:03:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ugensa.c,v 1.39 2019/05/09 02:43:35 mrg Exp $	*/
+/*	$NetBSD: ugensa.c,v 1.39.2.1 2020/06/07 17:03:11 martin Exp $	*/
 
 /*
  * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ugensa.c,v 1.39 2019/05/09 02:43:35 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugensa.c,v 1.39.2.1 2020/06/07 17:03:11 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -88,7 +88,6 @@ static const struct ugensa_type ugensa_d
 	{{ USB_VENDOR_DELL, USB_PRODUCT_DELL_HSDPA }, 0 },
 	{{ USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_FLEXPACKGPS }, 0 },
 	{{ USB_VENDOR_QUALCOMM_K, USB_PRODUCT_QUALCOMM_K_CDMA_MSM_K }, 0 },
-	{{ USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_USB305 }, 0 },
 	{{ USB_VENDOR_ZTE, USB_PRODUCT_ZTE_AC8700 }, 0 },
 
 	/*

Reply via email to