From af18794da416a2d5549b5c4db8e9ef6ec8937a95 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 17 Oct 2019 10:06:50 -0700 Subject: [PATCH] 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1865680 Reviewed-by: Stephen Barber --- usb_util/src/device.rs | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/usb_util/src/device.rs b/usb_util/src/device.rs index 3fc77e275e..b6aed6aaae 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` with a size in bytes at least as large as `size_in_bytes`. -fn vec_with_size_in_bytes(size_in_bytes: usize) -> Vec { - let rounded_size = (size_in_bytes + size_of::() - 1) / size_of::(); - 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(count: usize) -> Vec { - let element_space = count * size_of::(); - let vec_size_bytes = size_of::() + 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