aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/usb.c
diff options
context:
space:
mode:
authorSarah Sharp <sarah.a.sharp@linux.intel.com>2009-12-03 12:44:34 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-12-11 14:55:27 -0500
commit91017f9cf5fcfb601b8d583c896ac7de7d200c57 (patch)
treeca601c606ded366e14df0ac019ecd4c43c5b11d9 /drivers/usb/core/usb.c
parent06df572909080786e128eabdb2e39a12bce239de (diff)
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>
Diffstat (limited to 'drivers/usb/core/usb.c')
-rw-r--r--drivers/usb/core/usb.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index d1e9440799de..99e54586a545 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -64,6 +64,43 @@ MODULE_PARM_DESC(autosuspend, "default autosuspend delay");
64 64
65 65
66/** 66/**
67 * usb_find_alt_setting() - Given a configuration, find the alternate setting
68 * for the given interface.
69 * @config - the configuration to search (not necessarily the current config).
70 * @iface_num - interface number to search in
71 * @alt_num - alternate interface setting number to search for.
72 *
73 * Search the configuration's interface cache for the given alt setting.
74 */
75struct usb_host_interface *usb_find_alt_setting(
76 struct usb_host_config *config,
77 unsigned int iface_num,
78 unsigned int alt_num)
79{
80 struct usb_interface_cache *intf_cache = NULL;
81 int i;
82
83 for (i = 0; i < config->desc.bNumInterfaces; i++) {
84 if (config->intf_cache[i]->altsetting[0].desc.bInterfaceNumber
85 == iface_num) {
86 intf_cache = config->intf_cache[i];
87 break;
88 }
89 }
90 if (!intf_cache)
91 return NULL;
92 for (i = 0; i < intf_cache->num_altsetting; i++)
93 if (intf_cache->altsetting[i].desc.bAlternateSetting == alt_num)
94 return &intf_cache->altsetting[i];
95
96 printk(KERN_DEBUG "Did not find alt setting %u for intf %u, "
97 "config %u\n", alt_num, iface_num,
98 config->desc.bConfigurationValue);
99 return NULL;
100}
101EXPORT_SYMBOL_GPL(usb_find_alt_setting);
102
103/**
67 * usb_ifnum_to_if - get the interface object with a given interface number 104 * usb_ifnum_to_if - get the interface object with a given interface number
68 * @dev: the device whose current configuration is considered 105 * @dev: the device whose current configuration is considered
69 * @ifnum: the desired interface 106 * @ifnum: the desired interface