usb: gadget: epautoconf: remove ep and desc configuration from ep_matches()
authorRobert Baldyga <r.baldyga@samsung.com>
Fri, 31 Jul 2015 14:00:51 +0000 (16:00 +0200)
committerFelipe Balbi <balbi@ti.com>
Tue, 4 Aug 2015 17:27:44 +0000 (12:27 -0500)
As function ep_matches() is used to match endpoint with usb descriptor it's
highly unintuitive that it modifies endpoint and descriptor structures fields.
This patch moves code configuring ep and desc from ep_matches() to
usb_ep_autoconfig_ss(), so now function ep_matches() does nothing more than
its name suggests.

[ balbi@ti.com : fix build warning ]

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/epautoconf.c

index 4f66e9d733cdae69d0a092807e2edad8c617d54a..52658fe761d4911d48ef6e835dc02ba2a723df72 100644 (file)
@@ -82,13 +82,6 @@ ep_matches (
 
        }
 
-       /*
-        * If the protocol driver hasn't yet decided on wMaxPacketSize
-        * and wants to know the maximum possible, provide the info.
-        */
-       if (desc->wMaxPacketSize == 0)
-               desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket_limit);
-
        /* endpoint maxpacket size is an input parameter, except for bulk
         * where it's an output parameter representing the full speed limit.
         * the usb spec fixes high speed bulk maxpacket at 512 bytes.
@@ -119,31 +112,6 @@ ep_matches (
 
        /* MATCH!! */
 
-       /* report address */
-       desc->bEndpointAddress &= USB_DIR_IN;
-       if (isdigit (ep->name [2])) {
-               u8      num = simple_strtoul (&ep->name [2], NULL, 10);
-               desc->bEndpointAddress |= num;
-       } else if (desc->bEndpointAddress & USB_DIR_IN) {
-               if (++gadget->in_epnum > 15)
-                       return 0;
-               desc->bEndpointAddress = USB_DIR_IN | gadget->in_epnum;
-       } else {
-               if (++gadget->out_epnum > 15)
-                       return 0;
-               desc->bEndpointAddress |= gadget->out_epnum;
-       }
-
-       /* report (variable) full speed bulk maxpacket */
-       if ((USB_ENDPOINT_XFER_BULK == type) && !ep_comp) {
-               int size = ep->maxpacket_limit;
-
-               /* min() doesn't work on bitfields with gcc-3.5 */
-               if (size > 64)
-                       size = 64;
-               desc->wMaxPacketSize = cpu_to_le16(size);
-       }
-       ep->address = desc->bEndpointAddress;
        return 1;
 }
 
@@ -280,6 +248,40 @@ struct usb_ep *usb_ep_autoconfig_ss(
        /* Fail */
        return NULL;
 found_ep:
+
+       /*
+        * If the protocol driver hasn't yet decided on wMaxPacketSize
+        * and wants to know the maximum possible, provide the info.
+        */
+       if (desc->wMaxPacketSize == 0)
+               desc->wMaxPacketSize = cpu_to_le16(ep->maxpacket_limit);
+
+       /* report address */
+       desc->bEndpointAddress &= USB_DIR_IN;
+       if (isdigit(ep->name[2])) {
+               u8 num = simple_strtoul(&ep->name[2], NULL, 10);
+               desc->bEndpointAddress |= num;
+       } else if (desc->bEndpointAddress & USB_DIR_IN) {
+               if (++gadget->in_epnum > 15)
+                       return NULL;
+               desc->bEndpointAddress = USB_DIR_IN | gadget->in_epnum;
+       } else {
+               if (++gadget->out_epnum > 15)
+                       return NULL;
+               desc->bEndpointAddress |= gadget->out_epnum;
+       }
+
+       /* report (variable) full speed bulk maxpacket */
+       if ((type == USB_ENDPOINT_XFER_BULK) && !ep_comp) {
+               int size = ep->maxpacket_limit;
+
+               /* min() doesn't work on bitfields with gcc-3.5 */
+               if (size > 64)
+                       size = 64;
+               desc->wMaxPacketSize = cpu_to_le16(size);
+       }
+
+       ep->address = desc->bEndpointAddress;
        ep->desc = NULL;
        ep->comp_desc = NULL;
        ep->claimed = true;