summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-10-17 10:06:50 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-23 21:03:24 +0000
commitaf18794da416a2d5549b5c4db8e9ef6ec8937a95 (patch)
tree34c54c1b46efe8e6c2d8b2d1a67d9f0f4ab28890
parentf3c160e241f476d08daf2b3da7c31a8a63cf8255 (diff)
downloadcrosvm-af18794da416a2d5549b5c4db8e9ef6ec8937a95.tar
crosvm-af18794da416a2d5549b5c4db8e9ef6ec8937a95.tar.gz
crosvm-af18794da416a2d5549b5c4db8e9ef6ec8937a95.tar.bz2
crosvm-af18794da416a2d5549b5c4db8e9ef6ec8937a95.tar.lz
crosvm-af18794da416a2d5549b5c4db8e9ef6ec8937a95.tar.xz
crosvm-af18794da416a2d5549b5c4db8e9ef6ec8937a95.tar.zst
crosvm-af18794da416a2d5549b5c4db8e9ef6ec8937a95.zip
usb_util: use sys_util::vec_with_array_field
Drop the copy of vec_with_array_field now that it is available in a
common location.

BUG=None
TEST=cargo build

Change-Id: Ia272803737a4cb3e4e84213c48aa8e28c17bab2c
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865680
Reviewed-by: Stephen Barber <smbarber@chromium.org>
-rw-r--r--usb_util/src/device.rs21
1 files changed, 2 insertions, 19 deletions
diff --git a/usb_util/src/device.rs b/usb_util/src/device.rs
index 3fc77e2..b6aed6a 100644
--- a/usb_util/src/device.rs
+++ b/usb_util/src/device.rs
@@ -11,10 +11,10 @@ use libc::{EAGAIN, ENODEV, ENOENT};
 use std::convert::TryInto;
 use std::fs::File;
 use std::io::{Seek, SeekFrom};
-use std::mem::{size_of, size_of_val};
+use std::mem::size_of_val;
 use std::os::raw::{c_int, c_uint, c_ulong, c_void};
 use std::sync::Arc;
-use sys_util::handle_eintr_errno;
+use sys_util::{handle_eintr_errno, vec_with_array_field};
 
 /// Device represents a USB device.
 pub struct Device {
@@ -309,23 +309,6 @@ impl Device {
     }
 }
 
-// Returns a `Vec<T>` with a size in bytes at least as large as `size_in_bytes`.
-fn vec_with_size_in_bytes<T: Default>(size_in_bytes: usize) -> Vec<T> {
-    let rounded_size = (size_in_bytes + size_of::<T>() - 1) / size_of::<T>();
-    let mut v = Vec::with_capacity(rounded_size);
-    for _ in 0..rounded_size {
-        v.push(T::default())
-    }
-    v
-}
-
-// This function has been borrowed from kvm - see the doc comment there for details.
-fn vec_with_array_field<T: Default, F>(count: usize) -> Vec<T> {
-    let element_space = count * size_of::<F>();
-    let vec_size_bytes = size_of::<T>() + element_space;
-    vec_with_size_in_bytes(vec_size_bytes)
-}
-
 impl Transfer {
     fn urb(&self) -> &usb_sys::usbdevfs_urb {
         // self.urb is a Vec created with `vec_with_array_field`; the first entry is