Here's another diff to get rid of a driver attaching to a device in
unconfigured state.  I'd like to convert them all to enforce that a
USB device can only be matched if the stack already managed to set
its configuration.

I'm looking for tests and oks.

Index: uticom.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/uticom.c,v
retrieving revision 1.33
diff -u -p -r1.33 uticom.c
--- uticom.c    15 Mar 2018 00:42:41 -0000      1.33
+++ uticom.c    18 Nov 2018 17:11:16 -0000
@@ -190,7 +190,7 @@ uticom_match(struct device *parent, void
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != 1)
                return (UMATCH_NONE);
 
        return (usb_lookup(uticom_devs, uaa->vendor, uaa->product) != NULL ?
@@ -240,29 +240,12 @@ uticom_attach_hook(struct device *self)
        DPRINTF(("%s: uticom_attach: starting loading firmware\n",
            sc->sc_dev.dv_xname));
 
-       err = usbd_set_config_index(sc->sc_udev, UTICOM_CONFIG_INDEX, 1);
-       if (err) {
-               printf("%s: failed to set configuration: %s\n",
-                   sc->sc_dev.dv_xname, usbd_errstr(err));
-               usbd_deactivate(sc->sc_udev);
-               return;
-       }
-
        /* Get the config descriptor. */
        cdesc = usbd_get_config_descriptor(sc->sc_udev);
 
        if (cdesc == NULL) {
                printf("%s: failed to get configuration descriptor\n",
                    sc->sc_dev.dv_xname);
-               usbd_deactivate(sc->sc_udev);
-               return;
-       }
-
-       err = usbd_device2interface_handle(sc->sc_udev, UTICOM_IFACE_INDEX,
-           &sc->sc_iface);
-       if (err) {
-               printf("%s: failed to get interface: %s\n",
-                   sc->sc_dev.dv_xname, usbd_errstr(err));
                usbd_deactivate(sc->sc_udev);
                return;
        }

Reply via email to