Commit 13a791da authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

[PATCH] USB: usb_epnum_to_ep_desc only look

Original patch from oliverthered@oliverthered.com ... this
updates it:

  - usb_epnum_to_ep_desc() only looks at the active altsetting
  - docs clarified

It's possible some user mode drivers will have relied on the
previous buggy behavior, since usbfs uses this call.  The fix
will be for them to set the appropriate altsetting.
parent 24467ec6
...@@ -217,33 +217,35 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum) ...@@ -217,33 +217,35 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum)
/** /**
* usb_epnum_to_ep_desc - get the endpoint object with a given endpoint number * usb_epnum_to_ep_desc - get the endpoint object with a given endpoint number
* @dev: the device whose current configuration is considered * @dev: the device whose current configuration+altsettings is considered
* @epnum: the desired endpoint * @epnum: the desired endpoint, masked with USB_DIR_IN as appropriate.
* *
* This walks the device descriptor for the currently active configuration, * This walks the device descriptor for the currently active configuration,
* and returns a pointer to the endpoint with that particular endpoint * and returns a pointer to the endpoint with that particular endpoint
* number, or null. * number, or null.
* *
* Note that interface descriptors are not required to assign endpont * Note that interface descriptors are not required to list endpoint
* numbers sequentially, so that it would be incorrect to assume that * numbers in any standardized order, so that it would be wrong to
* the first endpoint in that descriptor corresponds to interface zero. * assume that ep2in precedes either ep5in, ep2out, or even ep1out.
* This routine helps device drivers avoid such mistakes. * This routine helps device drivers avoid such mistakes.
*/ */
struct usb_endpoint_descriptor * struct usb_endpoint_descriptor *
usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum) usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum)
{ {
int i, j, k; int i, k;
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
for (j = 0; j < dev->actconfig->interface[i]->num_altsetting; j++) struct usb_interface *intf;
for (k = 0; k < dev->actconfig->interface[i]-> struct usb_host_interface *alt;
altsetting[j].desc.bNumEndpoints; k++)
if (epnum == dev->actconfig->interface[i]-> /* only endpoints in current altseting are active */
altsetting[j].endpoint[k] intf = dev->actconfig->interface[i];
.desc.bEndpointAddress) alt = intf->altsetting + intf->act_altsetting;
return &dev->actconfig->interface[i]->
altsetting[j].endpoint[k] for (k = 0; k < alt->desc.bNumEndpoints; k++)
.desc; if (epnum == alt->endpoint[k].desc.bEndpointAddress)
return &alt->endpoint[k].desc;
}
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment