From 0dcbfa1176386d1e2f8f52947fe93004db195abe Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 18 Mar 2020 13:10:49 -0700 Subject: usb: avoid setting configuration when unnecessary On devices with only one configuration, skip the code that attempts to change the device's active configuration, since it must always be the single available configuration. This works around an issue observed with some USB devices (e.g. Servo Micro) where the initial Get Configuration control request fails with -EPIPE. BUG=chromium:1061382 BUG=b:151408644 TEST=Attach servo micro, see /dev/ttyUSB[012], screen /dev/ttyUSB0 Change-Id: Ic3333e1d70a0c57b090de64e4d3b7932ce2cf81d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2108871 Reviewed-by: Stephen Barber Tested-by: kokoro Tested-by: George Engelbrecht Commit-Queue: George Engelbrecht --- usb_util/src/device.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'usb_util') diff --git a/usb_util/src/device.rs b/usb_util/src/device.rs index aad77db..3ac1403 100644 --- a/usb_util/src/device.rs +++ b/usb_util/src/device.rs @@ -261,12 +261,8 @@ impl Device { } /// Get active config descriptor of this device. - pub fn get_active_config_descriptor(&self) -> Result { - let active_config = self.get_active_configuration()?; - match self - .device_descriptor_tree - .get_config_descriptor(active_config) - { + pub fn get_config_descriptor(&self, config: u8) -> Result { + match self.device_descriptor_tree.get_config_descriptor(config) { Some(config_descriptor) => Ok(config_descriptor.clone()), None => Err(Error::NoSuchDescriptor), } @@ -297,6 +293,11 @@ impl Device { Ok(active_config) } + /// Get the total number of configurations for this device. + pub fn get_num_configurations(&self) -> u8 { + self.device_descriptor_tree.bNumConfigurations + } + /// Clear the halt/stall condition for an endpoint. pub fn clear_halt(&self, ep_addr: u8) -> Result<()> { let endpoint: c_uint = ep_addr.into(); -- cgit 1.4.1