mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
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>
This commit is contained in:
parent
f3c160e241
commit
af18794da4
1 changed files with 2 additions and 19 deletions
|
@ -11,10 +11,10 @@ use libc::{EAGAIN, ENODEV, ENOENT};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Seek, SeekFrom};
|
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::os::raw::{c_int, c_uint, c_ulong, c_void};
|
||||||
use std::sync::Arc;
|
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.
|
/// Device represents a USB device.
|
||||||
pub struct 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 {
|
impl Transfer {
|
||||||
fn urb(&self) -> &usb_sys::usbdevfs_urb {
|
fn urb(&self) -> &usb_sys::usbdevfs_urb {
|
||||||
// self.urb is a Vec created with `vec_with_array_field`; the first entry is
|
// self.urb is a Vec created with `vec_with_array_field`; the first entry is
|
||||||
|
|
Loading…
Reference in a new issue