diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2019-05-01 16:36:26 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-05-10 15:26:01 -0700 |
commit | 659b1779e2c24fe4c8acf8b91dae066d46743e64 (patch) | |
tree | 1d5c681fee4052bfffc2f7e748ed8911b93ddef7 /usb_util | |
parent | d9990845398e40eb5bdac40610c895dacd9c1ee3 (diff) | |
download | crosvm-659b1779e2c24fe4c8acf8b91dae066d46743e64.tar crosvm-659b1779e2c24fe4c8acf8b91dae066d46743e64.tar.gz crosvm-659b1779e2c24fe4c8acf8b91dae066d46743e64.tar.bz2 crosvm-659b1779e2c24fe4c8acf8b91dae066d46743e64.tar.lz crosvm-659b1779e2c24fe4c8acf8b91dae066d46743e64.tar.xz crosvm-659b1779e2c24fe4c8acf8b91dae066d46743e64.tar.zst crosvm-659b1779e2c24fe4c8acf8b91dae066d46743e64.zip |
usb: remove pointless Options in UsbRequestSetup
The get_type and get_direction helpers return Options, even though they can only possibly return a non-None value; all bit patterns of the fields they are interpreting are defined. Drop the Options and return the enum values directly to simplify callers and remove dead code. Fix up a typo ("recipienet" -> "recipient") while we're in the neighborhood. BUG=chromium:831850 TEST=Test adb in Crostini Change-Id: Ie26a1ed1c15f5f17b5ae80be78ce5f8ff51fab28 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1593713 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'usb_util')
-rw-r--r-- | usb_util/src/types.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/usb_util/src/types.rs b/usb_util/src/types.rs index 0c7250d..eaebc70 100644 --- a/usb_util/src/types.rs +++ b/usb_util/src/types.rs @@ -142,31 +142,29 @@ impl UsbRequestSetup { } /// Get type of request. - pub fn get_type(&self) -> Option<ControlRequestType> { + pub fn get_type(&self) -> ControlRequestType { let ty = (self.request_type & CONTROL_REQUEST_TYPE) >> CONTROL_REQUEST_TYPE_OFFSET; match ty { - 0 => Some(ControlRequestType::Standard), - 1 => Some(ControlRequestType::Class), - 2 => Some(ControlRequestType::Vendor), - 3 => Some(ControlRequestType::Reserved), - _ => None, + 0 => ControlRequestType::Standard, + 1 => ControlRequestType::Class, + 2 => ControlRequestType::Vendor, + _ => ControlRequestType::Reserved, } } /// Get request direction. - pub fn get_direction(&self) -> Option<ControlRequestDataPhaseTransferDirection> { + pub fn get_direction(&self) -> ControlRequestDataPhaseTransferDirection { let dir = (self.request_type & DATA_PHASE_DIRECTION) >> DATA_PHASE_DIRECTION_OFFSET; match dir { - 0 => Some(ControlRequestDataPhaseTransferDirection::HostToDevice), - 1 => Some(ControlRequestDataPhaseTransferDirection::DeviceToHost), - _ => None, + 0 => ControlRequestDataPhaseTransferDirection::HostToDevice, + _ => ControlRequestDataPhaseTransferDirection::DeviceToHost, } } /// Get recipient of this control transfer. pub fn get_recipient(&self) -> ControlRequestRecipient { - let recipienet = self.request_type & REQUEST_RECIPIENT_TYPE; - match recipienet { + let recipient = self.request_type & REQUEST_RECIPIENT_TYPE; + match recipient { 0 => ControlRequestRecipient::Device, 1 => ControlRequestRecipient::Interface, 2 => ControlRequestRecipient::Endpoint, |