USB: Refactor code to find alternate interface settings.
Refactor out the code to find alternate interface settings into
usb_find_alt_setting(). Print a debugging message and return null if the
alt setting is not found.
While we're at it, correct a bug in the refactored code. The interfaces
in the configuration's interface cache are not necessarily in numerical
order, so we can't just use the interface number as an array index. Loop
through the interface caches, looking for the correct interface.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index daac042..fc235b0 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1606,7 +1606,6 @@
struct usb_interface *new_intf)
{
int num_intfs, i, j;
- struct usb_interface_cache *intf_cache;
struct usb_host_interface *alt = NULL;
int ret = 0;
struct usb_hcd *hcd;
@@ -1654,15 +1653,8 @@
}
}
for (i = 0; i < num_intfs; ++i) {
-
- /* Dig the endpoints for alt setting 0 out of the
- * interface cache for this interface
- */
- intf_cache = new_config->intf_cache[i];
- for (j = 0; j < intf_cache->num_altsetting; j++) {
- if (intf_cache->altsetting[j].desc.bAlternateSetting == 0)
- alt = &intf_cache->altsetting[j];
- }
+ /* Set up endpoints for alternate interface setting 0 */
+ alt = usb_find_alt_setting(new_config, i, 0);
if (!alt) {
printk(KERN_DEBUG "Did not find alt setting 0 for intf %d\n", i);
continue;