summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-08-19 14:06:17 -0700
committerCommit Bot <commit-bot@chromium.org>2019-08-26 23:41:53 +0000
commit034f7a3a1c43cd63a4106c076e0053abe28ff992 (patch)
treebcc41213de21366a34438cffdba71a7b197b62f5
parente7e7e51fb064cdec2b7a55f08bc18c9fa01a1180 (diff)
downloadcrosvm-034f7a3a1c43cd63a4106c076e0053abe28ff992.tar
crosvm-034f7a3a1c43cd63a4106c076e0053abe28ff992.tar.gz
crosvm-034f7a3a1c43cd63a4106c076e0053abe28ff992.tar.bz2
crosvm-034f7a3a1c43cd63a4106c076e0053abe28ff992.tar.lz
crosvm-034f7a3a1c43cd63a4106c076e0053abe28ff992.tar.xz
crosvm-034f7a3a1c43cd63a4106c076e0053abe28ff992.tar.zst
crosvm-034f7a3a1c43cd63a4106c076e0053abe28ff992.zip
devices: pci: replace byteorder with from_le_bytes()
Use the standardized from_le_bytes() functions rather than the byteorder
crate.

BUG=None
TEST=./build_test

Change-Id: I07a062bf63c5d3ae1e25f403713bf9a1677e8cba
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1761155
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
-rw-r--r--Cargo.lock1
-rw-r--r--devices/Cargo.toml1
-rw-r--r--devices/src/pci/pci_configuration.rs7
-rw-r--r--devices/src/pci/pci_root.rs6
4 files changed, 6 insertions, 9 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6939007..ebba197 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -142,7 +142,6 @@ version = "0.1.0"
 dependencies = [
  "audio_streams 0.1.0",
  "bit_field 0.1.0",
- "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "data_model 0.1.0",
  "enumn 0.1.0",
  "gpu_buffer 0.1.0",
diff --git a/devices/Cargo.toml b/devices/Cargo.toml
index 3e1e554..47f55df 100644
--- a/devices/Cargo.toml
+++ b/devices/Cargo.toml
@@ -14,7 +14,6 @@ x = ["gpu_display/x"]
 [dependencies]
 audio_streams = "*"
 bit_field = { path = "../bit_field" }
-byteorder = "*"
 data_model = { path = "../data_model" }
 enumn = { path = "../enumn" }
 gpu_buffer = { path = "../gpu_buffer", optional = true }
diff --git a/devices/src/pci/pci_configuration.rs b/devices/src/pci/pci_configuration.rs
index e65dd85..5e268fe 100644
--- a/devices/src/pci/pci_configuration.rs
+++ b/devices/src/pci/pci_configuration.rs
@@ -2,8 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-use byteorder::{ByteOrder, LittleEndian};
-
+use std::convert::TryInto;
 use std::fmt::{self, Display};
 
 use crate::pci::PciInterruptPin;
@@ -300,8 +299,8 @@ impl PciConfiguration {
         let reg_offset = reg_idx * 4 + offset as usize;
         match data.len() {
             1 => self.write_byte(reg_offset, data[0]),
-            2 => self.write_word(reg_offset, LittleEndian::read_u16(data)),
-            4 => self.write_dword(reg_offset, LittleEndian::read_u32(data)),
+            2 => self.write_word(reg_offset, u16::from_le_bytes(data.try_into().unwrap())),
+            4 => self.write_dword(reg_offset, u32::from_le_bytes(data.try_into().unwrap())),
             _ => (),
         }
     }
diff --git a/devices/src/pci/pci_root.rs b/devices/src/pci/pci_root.rs
index 300b951..eef642e 100644
--- a/devices/src/pci/pci_root.rs
+++ b/devices/src/pci/pci_root.rs
@@ -2,10 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+use std::convert::TryInto;
 use std::os::unix::io::RawFd;
 use std::sync::Arc;
 
-use byteorder::{ByteOrder, LittleEndian};
 use sync::Mutex;
 
 use crate::pci::pci_configuration::{
@@ -184,9 +184,9 @@ impl PciConfigIo {
             ),
             2 => (
                 0x0000_ffff << (offset * 16),
-                ((data[1] as u32) << 8 | data[0] as u32) << (offset * 16),
+                u32::from(u16::from_le_bytes(data.try_into().unwrap())) << (offset * 16),
             ),
-            4 => (0xffff_ffff, LittleEndian::read_u32(data)),
+            4 => (0xffff_ffff, u32::from_le_bytes(data.try_into().unwrap())),
             _ => return,
         };
         self.config_address = (self.config_address & !mask) | value;