...and instead let the stack do it for you.

Changing the configuration of a device implies fetching and parsing
descriptors.  If anything bad happen, most of the device below are
left attached but unconfigured, and many of them do not even
deactivate the device.

Test reports and oks welcome.

Index: if_atu.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_atu.c,v
retrieving revision 1.119
diff -u -p -r1.119 if_atu.c
--- if_atu.c    13 Apr 2016 11:03:37 -0000      1.119
+++ if_atu.c    9 Sep 2016 15:39:39 -0000
@@ -1102,7 +1102,7 @@ atu_match(struct device *parent, void *m
        struct usb_attach_arg   *uaa = aux;
        int                     i;
 
-       if (!uaa->iface)
+       if (uaa->iface == NULL || uaa->configno != ATU_CONFIG_NO)
                return(UMATCH_NONE);
 
        for (i = 0; i < nitems(atu_devs); i++) {
@@ -1252,13 +1252,6 @@ atu_attach(struct device *parent, struct
 
        sc->atu_unit = self->dv_unit;
        sc->atu_udev = dev;
-
-       err = usbd_set_config_no(dev, ATU_CONFIG_NO, 1);
-       if (err) {
-               printf("%s: setting config no failed\n",
-                   sc->atu_dev.dv_xname);
-               goto fail;
-       }
 
        err = usbd_device2interface_handle(dev, ATU_IFACE_IDX, &sc->atu_iface);
        if (err) {
Index: if_cue.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_cue.c,v
retrieving revision 1.75
diff -u -p -r1.75 if_cue.c
--- if_cue.c    13 Apr 2016 11:03:37 -0000      1.75
+++ if_cue.c    9 Sep 2016 15:49:23 -0000
@@ -415,7 +415,7 @@ cue_match(struct device *parent, void *m
 {
        struct usb_attach_arg   *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != CUE_CONFIG_NO)
                return (UMATCH_NONE);
 
        return (usb_lookup(cue_devs, uaa->vendor, uaa->product) != NULL ?
@@ -444,14 +444,6 @@ cue_attach(struct device *parent, struct
        DPRINTFN(5,(" : cue_attach: sc=%p, dev=%p", sc, dev));
 
        sc->cue_udev = dev;
-
-       err = usbd_set_config_no(dev, CUE_CONFIG_NO, 1);
-       if (err) {
-               printf("%s: setting config no failed\n",
-                   sc->cue_dev.dv_xname);
-               return;
-       }
-
        sc->cue_product = uaa->product;
        sc->cue_vendor = uaa->vendor;
 
Index: if_mos.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_mos.c,v
retrieving revision 1.36
diff -u -p -r1.36 if_mos.c
--- if_mos.c    13 Apr 2016 11:03:37 -0000      1.36
+++ if_mos.c    9 Sep 2016 15:40:38 -0000
@@ -607,7 +607,7 @@ mos_match(struct device *parent, void *m
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (!uaa->iface)
+       if (uaa->iface == NULL || uaa->configno != MOS_CONFIG_NO)
                return(UMATCH_NONE);
 
        return (mos_lookup(uaa->vendor, uaa->product) != NULL ?
@@ -634,13 +634,6 @@ mos_attach(struct device *parent, struct
 
        sc->mos_udev = dev;
        sc->mos_unit = self->dv_unit;
-
-       err = usbd_set_config_no(dev, MOS_CONFIG_NO, 1);
-       if (err) {
-               printf("%s: getting interface handle failed\n",
-                   sc->mos_dev.dv_xname);
-               return;
-       }
 
        usb_init_task(&sc->mos_tick_task, mos_tick_task, sc,
            USB_TASK_TYPE_GENERIC);
Index: if_otus.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_otus.c,v
retrieving revision 1.53
diff -u -p -r1.53 if_otus.c
--- if_otus.c   13 Apr 2016 11:03:37 -0000      1.53
+++ if_otus.c   9 Sep 2016 15:41:05 -0000
@@ -176,7 +176,7 @@ otus_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(otus_devs, uaa->vendor, uaa->product) != NULL) ?
@@ -198,12 +198,6 @@ otus_attach(struct device *parent, struc
 
        sc->amrr.amrr_min_success_threshold =  1;
        sc->amrr.amrr_max_success_threshold = 10;
-
-       if (usbd_set_config_no(sc->sc_udev, 1, 0) != 0) {
-               printf("%s: could not set configuration no\n",
-                   sc->sc_dev.dv_xname);
-               return;
-       }
 
        /* Get the first interface handle. */
        error = usbd_device2interface_handle(sc->sc_udev, 0, &sc->sc_iface);
Index: if_ral.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_ral.c,v
retrieving revision 1.140
diff -u -p -r1.140 if_ral.c
--- if_ral.c    20 Jul 2016 10:24:43 -0000      1.140
+++ if_ral.c    9 Sep 2016 15:41:31 -0000
@@ -196,7 +196,7 @@ ural_match(struct device *parent, void *
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != RAL_CONFIG_NO)
                return UMATCH_NONE;
 
        return (usb_lookup(ural_devs, uaa->vendor, uaa->product) != NULL) ?
@@ -216,12 +216,6 @@ ural_attach(struct device *parent, struc
        int i;
 
        sc->sc_udev = uaa->device;
-
-       if (usbd_set_config_no(sc->sc_udev, RAL_CONFIG_NO, 0) != 0) {
-               printf("%s: could not set configuration no\n",
-                   sc->sc_dev.dv_xname);
-               return;
-       }
 
        /* get the first interface handle */
        error = usbd_device2interface_handle(sc->sc_udev, RAL_IFACE_INDEX,
Index: if_uath.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_uath.c,v
retrieving revision 1.77
diff -u -p -r1.77 if_uath.c
--- if_uath.c   13 Apr 2016 11:03:37 -0000      1.77
+++ if_uath.c   9 Sep 2016 15:42:15 -0000
@@ -191,7 +191,7 @@ uath_match(struct device *parent, void *
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != UATH_CONFIG_NO)
                return UMATCH_NONE;
 
        return (uath_lookup(uaa->vendor, uaa->product) != NULL) ?
@@ -244,12 +244,6 @@ uath_attach(struct device *parent, struc
        sc->sc_port = uaa->port;
 
        sc->sc_flags = uath_lookup(uaa->vendor, uaa->product)->flags;
-
-       if (usbd_set_config_no(sc->sc_udev, UATH_CONFIG_NO, 0) != 0) {
-               printf("%s: could not set configuration no\n",
-                   sc->sc_dev.dv_xname);
-               return;
-       }
 
        /* get the first interface handle */
        error = usbd_device2interface_handle(sc->sc_udev, UATH_IFACE_INDEX,
Index: if_upgt.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_upgt.c,v
retrieving revision 1.77
diff -u -p -r1.77 if_upgt.c
--- if_upgt.c   13 Apr 2016 11:03:37 -0000      1.77
+++ if_upgt.c   9 Sep 2016 15:42:43 -0000
@@ -180,7 +180,7 @@ upgt_match(struct device *parent, void *
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != UPGT_CONFIG_NO)
                return (UMATCH_NONE);
 
        if (usb_lookup(upgt_devs_1, uaa->vendor, uaa->product) != NULL)
@@ -210,13 +210,6 @@ upgt_attach(struct device *parent, struc
        /* check device type */
        if (upgt_device_type(sc, uaa->vendor, uaa->product) != 0)
                return;
-
-       /* set configuration number */
-       if (usbd_set_config_no(sc->sc_udev, UPGT_CONFIG_NO, 0) != 0) {
-               printf("%s: could not set configuration no!\n",
-                   sc->sc_dev.dv_xname);
-               return;
-       }
 
        /* get the first interface handle */
        error = usbd_device2interface_handle(sc->sc_udev, UPGT_IFACE_INDEX,
Index: if_upl.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_upl.c,v
retrieving revision 1.71
diff -u -p -r1.71 if_upl.c
--- if_upl.c    13 Apr 2016 11:03:37 -0000      1.71
+++ if_upl.c    9 Sep 2016 15:43:11 -0000
@@ -187,7 +187,7 @@ upl_match(struct device *parent, void *m
 {
        struct usb_attach_arg           *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != UPL_CONFIG_NO)
                return (UMATCH_NONE);
 
        return (usb_lookup(upl_devs, uaa->vendor, uaa->product) != NULL ?
@@ -209,13 +209,6 @@ upl_attach(struct device *parent, struct
        int                     i;
 
        DPRINTFN(5,(" : upl_attach: sc=%p, dev=%p", sc, dev));
-
-       err = usbd_set_config_no(dev, UPL_CONFIG_NO, 1);
-       if (err) {
-               printf("%s: setting config no failed\n",
-                   sc->sc_dev.dv_xname);
-               return;
-       }
 
        sc->sc_udev = dev;
 
Index: if_url.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_url.c,v
retrieving revision 1.80
diff -u -p -r1.80 if_url.c
--- if_url.c    13 Apr 2016 11:03:37 -0000      1.80
+++ if_url.c    9 Sep 2016 15:43:43 -0000
@@ -163,7 +163,7 @@ url_match(struct device *parent, void *m
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != URL_CONFIG_NO)
                return (UMATCH_NONE);
 
        return (url_lookup(uaa->vendor, uaa->product) != NULL ?
@@ -187,13 +187,6 @@ url_attach(struct device *parent, struct
        int i, s;
 
        sc->sc_udev = dev;
-
-       /* Move the device into the configured state. */
-       err = usbd_set_config_no(dev, URL_CONFIG_NO, 1);
-       if (err) {
-               printf("%s: setting config no failed\n", devname);
-               goto bad;
-       }
 
        usb_init_task(&sc->sc_tick_task, url_tick_task, sc,
            USB_TASK_TYPE_GENERIC);
Index: uberry.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/uberry.c,v
retrieving revision 1.23
diff -u -p -r1.23 uberry.c
--- uberry.c    19 Dec 2014 22:44:59 -0000      1.23
+++ uberry.c    9 Sep 2016 15:44:23 -0000
@@ -74,7 +74,7 @@ uberry_match(struct device *parent, void
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != UBERRY_CONFIG_NO)
                return UMATCH_NONE;
 
        return (usb_lookup(uberry_devices, uaa->vendor, uaa->product) != NULL) ?
@@ -91,17 +91,6 @@ uberry_attach(struct device *parent, str
        sc->sc_udev = uaa->device;
 
        dd = usbd_get_device_descriptor(uaa->device);
-
-       /* Enable configuration, to keep it connected... */
-       if (usbd_set_config_no(sc->sc_udev, UBERRY_CONFIG_NO, 1) != 0) {
-               /*
-                * Really ancient (ie. 7250) devices when off will
-                * only charge at 100mA when turned off.
-                */
-               printf("%s: Charging at %dmA\n", sc->sc_dev.dv_xname,
-                   sc->sc_udev->power);
-               return;
-       }
 
        printf("%s: Charging at %dmA", sc->sc_dev.dv_xname,
            sc->sc_udev->power);
Index: udl.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/udl.c,v
retrieving revision 1.84
diff -u -p -r1.84 udl.c
--- udl.c       11 Dec 2015 16:07:02 -0000      1.84
+++ udl.c       9 Sep 2016 15:45:01 -0000
@@ -258,7 +258,7 @@ udl_match(struct device *parent, void *m
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != 1)
                return (UMATCH_NONE);
 
        if (udl_lookup(uaa->vendor, uaa->product) != NULL)
@@ -303,12 +303,6 @@ udl_attach(struct device *parent, struct
                if (udl_select_chip(sc))
                        return;
 
-       /*
-        * Set device configuration descriptor number.
-        */
-       error = usbd_set_config_no(sc->sc_udev, 1, 0);
-       if (error != USBD_NORMAL_COMPLETION)
-               return;
 
        /*
         * Create device handle to interface descriptor.
Index: udsbr.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/udsbr.c,v
retrieving revision 1.26
diff -u -p -r1.26 udsbr.c
--- udsbr.c     14 Mar 2015 03:38:49 -0000      1.26
+++ udsbr.c     9 Sep 2016 15:47:56 -0000
@@ -114,7 +114,7 @@ udsbr_match(struct device *parent, void 
 
        DPRINTFN(50,("udsbr_match\n"));
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != UDSBR_CONFIG_NO)
                return (UMATCH_NONE);
 
        if (uaa->vendor != USB_VENDOR_CYPRESS ||
@@ -129,21 +129,8 @@ udsbr_attach(struct device *parent, stru
        struct udsbr_softc      *sc = (struct udsbr_softc *)self;
        struct usb_attach_arg   *uaa = aux;
        struct usbd_device      *dev = uaa->device;
-       usbd_status             err;
-
-       DPRINTFN(10,("udsbr_attach: sc=%p\n", sc));
-
-       err = usbd_set_config_no(dev, UDSBR_CONFIG_NO, 1);
-       if (err) {
-               printf("%s: setting config no failed\n",
-                   sc->sc_dev.dv_xname);
-               return;
-       }
 
        sc->sc_udev = dev;
-
-       DPRINTFN(10, ("udsbr_attach: %p\n", sc->sc_udev));
-
        sc->sc_child = radio_attach_mi(&udsbr_hw_if, sc, &sc->sc_dev);
 }
 
Index: uipaq.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/uipaq.c,v
retrieving revision 1.25
diff -u -p -r1.25 uipaq.c
--- uipaq.c     14 Mar 2015 03:38:50 -0000      1.25
+++ uipaq.c     9 Sep 2016 15:46:24 -0000
@@ -139,7 +139,7 @@ uipaq_match(struct device *parent, void 
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != UIPAQ_CONFIG_NO)
                return (UMATCH_NONE);
 
        DPRINTFN(20,("uipaq: vendor=0x%x, product=0x%x\n",
@@ -164,14 +164,6 @@ uipaq_attach(struct device *parent, stru
        struct ucom_attach_args uca;
 
        DPRINTFN(10,("\nuipaq_attach: sc=%p\n", sc));
-
-       /* Move the device into the configured state. */
-       err = usbd_set_config_no(dev, UIPAQ_CONFIG_NO, 1);
-       if (err) {
-               printf(": failed to set configuration, err=%s\n",
-                   usbd_errstr(err));
-               goto bad;
-       }
 
        err = usbd_device2interface_handle(dev, UIPAQ_IFACE_INDEX, &iface);
        if (err) {
Index: uow.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/uow.c,v
retrieving revision 1.34
diff -u -p -r1.34 uow.c
--- uow.c       31 Aug 2015 07:32:15 -0000      1.34
+++ uow.c       9 Sep 2016 15:46:51 -0000
@@ -100,7 +100,7 @@ uow_match(struct device *parent, void *m
 {
        struct usb_attach_arg *uaa = aux;
 
-       if (uaa->iface != NULL)
+       if (uaa->iface == NULL || uaa->configno != DS2490_USB_CONFIG)
                return (UMATCH_NONE);
 
        return ((usb_lookup(uow_devs, uaa->vendor, uaa->product) != NULL) ?
@@ -120,15 +120,6 @@ uow_attach(struct device *parent, struct
        int i;
 
        sc->sc_udev = uaa->device;
-
-       /* Set USB configuration */
-       if ((error = usbd_set_config_no(sc->sc_udev,
-           DS2490_USB_CONFIG, 0)) != 0) {
-               printf("%s: failed to set config %d: %s\n",
-                   sc->sc_dev.dv_xname, DS2490_USB_CONFIG,
-                   usbd_errstr(error));
-               return;
-       }
 
        /* Get interface handle */
        if ((error = usbd_device2interface_handle(sc->sc_udev,
Index: usps.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/usps.c,v
retrieving revision 1.7
diff -u -p -r1.7 usps.c
--- usps.c      12 Jul 2014 21:24:33 -0000      1.7
+++ usps.c      9 Sep 2016 15:47:33 -0000
@@ -134,7 +134,7 @@ usps_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;
 
        if (usps_lookup(uaa->vendor, uaa->product) == NULL)
@@ -157,15 +157,7 @@ usps_attach(struct device *parent, struc
        sc->sc_udev = uaa->device;
 
 #define USPS_USB_IFACE 0
-#define USPS_USB_CONFIG 1
 
-       /* set configuration */
-       if ((err = usbd_set_config_no(sc->sc_udev, USPS_USB_CONFIG, 0)) != 0){
-               printf("%s: failed to set config %d: %s\n",
-                   sc->sc_dev.dv_xname, USPS_USB_CONFIG, usbd_errstr(err));
-               return;
-       }
-               
        /* get interface handle */
        if ((err = usbd_device2interface_handle(sc->sc_udev, USPS_USB_IFACE,
                &sc->sc_iface)) != 0) {

Reply via email to