summary refs log tree commit diff
path: root/devices/src/usb
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2019-03-08 16:56:14 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-04-08 02:51:37 -0700
commitfdac5ede468e0fddfe527d6108430ee932b02fc3 (patch)
tree398c2ace79eea2babb4439810c43b793068fd8cc /devices/src/usb
parent98895ac05d42ed346a161035134600b0d0e0bb87 (diff)
downloadcrosvm-fdac5ede468e0fddfe527d6108430ee932b02fc3.tar
crosvm-fdac5ede468e0fddfe527d6108430ee932b02fc3.tar.gz
crosvm-fdac5ede468e0fddfe527d6108430ee932b02fc3.tar.bz2
crosvm-fdac5ede468e0fddfe527d6108430ee932b02fc3.tar.lz
crosvm-fdac5ede468e0fddfe527d6108430ee932b02fc3.tar.xz
crosvm-fdac5ede468e0fddfe527d6108430ee932b02fc3.tar.zst
crosvm-fdac5ede468e0fddfe527d6108430ee932b02fc3.zip
edition: Use dyn syntax for trait objects
Found by running: `cargo rustc -- -D bare_trait_objects`

Bare trait objects like `&Trait` and `Box<Trait>` are soft-deprecated in
2018 edition and will start warning at some point.

As part of this, I replaced `Box<Trait + 'static>` with `Box<dyn Trait>`
because the 'static bound is implied for boxed trait objects.

TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu
TEST=local kokoro

Change-Id: I41c4f13530bece8a34a8ed1c1afd7035b8f86f19
Reviewed-on: https://chromium-review.googlesource.com/1513059
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
Diffstat (limited to 'devices/src/usb')
-rw-r--r--devices/src/usb/host_backend/context.rs4
-rw-r--r--devices/src/usb/host_backend/host_backend_device_provider.rs10
-rw-r--r--devices/src/usb/host_backend/host_device.rs4
-rw-r--r--devices/src/usb/host_backend/usb_endpoint.rs4
-rw-r--r--devices/src/usb/host_backend/utils.rs2
-rw-r--r--devices/src/usb/xhci/device_slot.rs10
-rw-r--r--devices/src/usb/xhci/intr_resample_handler.rs2
-rw-r--r--devices/src/usb/xhci/ring_buffer_controller.rs2
-rw-r--r--devices/src/usb/xhci/ring_buffer_stop_cb.rs4
-rw-r--r--devices/src/usb/xhci/usb_hub.rs11
-rw-r--r--devices/src/usb/xhci/xhci.rs4
-rw-r--r--devices/src/usb/xhci/xhci_backend_device_provider.rs2
-rw-r--r--devices/src/usb/xhci/xhci_controller.rs4
-rw-r--r--devices/src/usb/xhci/xhci_transfer.rs2
14 files changed, 34 insertions, 31 deletions
diff --git a/devices/src/usb/host_backend/context.rs b/devices/src/usb/host_backend/context.rs
index d4c60e3..dc35a9f 100644
--- a/devices/src/usb/host_backend/context.rs
+++ b/devices/src/usb/host_backend/context.rs
@@ -17,7 +17,7 @@ use vm_control::MaybeOwnedFd;
 pub struct Context {
     context: LibUsbContext,
     event_loop: Arc<EventLoop>,
-    event_handler: Arc<EventHandler>,
+    event_handler: Arc<dyn EventHandler>,
 }
 
 impl Context {
@@ -124,7 +124,7 @@ impl EventHandler for LibUsbEventHandler {
 
 struct PollfdChangeHandler {
     event_loop: Arc<EventLoop>,
-    event_handler: Weak<EventHandler>,
+    event_handler: Weak<dyn EventHandler>,
 }
 
 impl LibUsbPollfdChangeHandler for PollfdChangeHandler {
diff --git a/devices/src/usb/host_backend/host_backend_device_provider.rs b/devices/src/usb/host_backend/host_backend_device_provider.rs
index 32c5e9a..6aca696 100644
--- a/devices/src/usb/host_backend/host_backend_device_provider.rs
+++ b/devices/src/usb/host_backend/host_backend_device_provider.rs
@@ -55,7 +55,7 @@ impl HostBackendDeviceProvider {
 
     fn start_helper(
         &mut self,
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         event_loop: Arc<EventLoop>,
         hub: Arc<UsbHub>,
     ) -> Result<()> {
@@ -67,7 +67,7 @@ impl HostBackendDeviceProvider {
                 let job_queue =
                     AsyncJobQueue::init(&event_loop).map_err(Error::StartAsyncJobQueue)?;
                 let inner = Arc::new(ProviderInner::new(fail_handle, job_queue, ctx, sock, hub));
-                let handler: Arc<EventHandler> = inner.clone();
+                let handler: Arc<dyn EventHandler> = inner.clone();
                 event_loop
                     .add_event(
                         &inner.sock,
@@ -93,7 +93,7 @@ impl HostBackendDeviceProvider {
 impl XhciBackendDeviceProvider for HostBackendDeviceProvider {
     fn start(
         &mut self,
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         event_loop: Arc<EventLoop>,
         hub: Arc<UsbHub>,
     ) -> std::result::Result<(), ()> {
@@ -119,7 +119,7 @@ impl XhciBackendDeviceProvider for HostBackendDeviceProvider {
 
 /// ProviderInner listens to control socket.
 pub struct ProviderInner {
-    fail_handle: Arc<FailHandle>,
+    fail_handle: Arc<dyn FailHandle>,
     job_queue: Arc<AsyncJobQueue>,
     ctx: Context,
     sock: MsgSocket<UsbControlResult, UsbControlCommand>,
@@ -128,7 +128,7 @@ pub struct ProviderInner {
 
 impl ProviderInner {
     fn new(
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         job_queue: Arc<AsyncJobQueue>,
         ctx: Context,
         sock: MsgSocket<UsbControlResult, UsbControlCommand>,
diff --git a/devices/src/usb/host_backend/host_device.rs b/devices/src/usb/host_backend/host_device.rs
index ae3faa0..ca00da8 100644
--- a/devices/src/usb/host_backend/host_device.rs
+++ b/devices/src/usb/host_backend/host_device.rs
@@ -83,7 +83,7 @@ impl HostToDeviceControlRequest {
 
 /// Host device is a device connected to host.
 pub struct HostDevice {
-    fail_handle: Arc<FailHandle>,
+    fail_handle: Arc<dyn FailHandle>,
     // Endpoints only contains data endpoints (1 to 30). Control transfers are handled at device
     // level.
     endpoints: Vec<UsbEndpoint>,
@@ -106,7 +106,7 @@ impl Drop for HostDevice {
 impl HostDevice {
     /// Create a new host device.
     pub fn new(
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         job_queue: Arc<AsyncJobQueue>,
         device: LibUsbDevice,
         device_handle: DeviceHandle,
diff --git a/devices/src/usb/host_backend/usb_endpoint.rs b/devices/src/usb/host_backend/usb_endpoint.rs
index fcdacaa..ba1d359 100644
--- a/devices/src/usb/host_backend/usb_endpoint.rs
+++ b/devices/src/usb/host_backend/usb_endpoint.rs
@@ -22,7 +22,7 @@ use utils::FailHandle;
 
 /// Isochronous, Bulk or Interrupt endpoint.
 pub struct UsbEndpoint {
-    fail_handle: Arc<FailHandle>,
+    fail_handle: Arc<dyn FailHandle>,
     job_queue: Arc<AsyncJobQueue>,
     device_handle: Arc<Mutex<DeviceHandle>>,
     endpoint_number: u8,
@@ -33,7 +33,7 @@ pub struct UsbEndpoint {
 impl UsbEndpoint {
     /// Create new endpoint. This function will panic if endpoint type is control.
     pub fn new(
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         job_queue: Arc<AsyncJobQueue>,
         device_handle: Arc<Mutex<DeviceHandle>>,
         endpoint_number: u8,
diff --git a/devices/src/usb/host_backend/utils.rs b/devices/src/usb/host_backend/utils.rs
index 9f1abc9..60e29d7 100644
--- a/devices/src/usb/host_backend/utils.rs
+++ b/devices/src/usb/host_backend/utils.rs
@@ -44,7 +44,7 @@ pub fn update_transfer_state<T: UsbTransferBuffer>(
 
 /// Helper function to submit usb_transfer to device handle.
 pub fn submit_transfer<T: UsbTransferBuffer>(
-    fail_handle: Arc<FailHandle>,
+    fail_handle: Arc<dyn FailHandle>,
     job_queue: &Arc<AsyncJobQueue>,
     xhci_transfer: Arc<XhciTransfer>,
     device_handle: &Arc<Mutex<DeviceHandle>>,
diff --git a/devices/src/usb/xhci/device_slot.rs b/devices/src/usb/xhci/device_slot.rs
index fcac44d..6f4e8f3 100644
--- a/devices/src/usb/xhci/device_slot.rs
+++ b/devices/src/usb/xhci/device_slot.rs
@@ -77,14 +77,14 @@ fn valid_endpoint_id(endpoint_id: u8) -> bool {
 
 #[derive(Clone)]
 pub struct DeviceSlots {
-    fail_handle: Arc<FailHandle>,
+    fail_handle: Arc<dyn FailHandle>,
     hub: Arc<UsbHub>,
     slots: Vec<Arc<DeviceSlot>>,
 }
 
 impl DeviceSlots {
     pub fn new(
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         dcbaap: Register<u64>,
         hub: Arc<UsbHub>,
         interrupter: Arc<Mutex<Interrupter>>,
@@ -336,7 +336,7 @@ impl DeviceSlot {
     /// Disable this device slot. If the slot is not enabled, callback will be invoked immediately
     /// with error. Otherwise, callback will be invoked when all trc is stopped.
     pub fn disable<C: FnMut(TrbCompletionCode) -> std::result::Result<(), ()> + 'static + Send>(
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         slot: &Arc<DeviceSlot>,
         mut callback: C,
     ) -> Result<()> {
@@ -577,7 +577,7 @@ impl DeviceSlot {
     pub fn reset_slot<
         C: FnMut(TrbCompletionCode) -> std::result::Result<(), ()> + 'static + Send,
     >(
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         slot: &Arc<DeviceSlot>,
         mut callback: C,
     ) -> Result<()> {
@@ -621,7 +621,7 @@ impl DeviceSlot {
         C: FnMut(TrbCompletionCode) -> std::result::Result<(), ()> + 'static + Send,
     >(
         &self,
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         endpoint_id: u8,
         mut cb: C,
     ) -> Result<()> {
diff --git a/devices/src/usb/xhci/intr_resample_handler.rs b/devices/src/usb/xhci/intr_resample_handler.rs
index 8c7ff99..d4faa71 100644
--- a/devices/src/usb/xhci/intr_resample_handler.rs
+++ b/devices/src/usb/xhci/intr_resample_handler.rs
@@ -25,7 +25,7 @@ impl IntrResampleHandler {
             interrupter,
             resample_evt,
         });
-        let tmp_handler: Arc<EventHandler> = handler.clone();
+        let tmp_handler: Arc<dyn EventHandler> = handler.clone();
         if let Err(e) = event_loop.add_event(
             &handler.resample_evt,
             WatchingEvents::empty().set_read(),
diff --git a/devices/src/usb/xhci/ring_buffer_controller.rs b/devices/src/usb/xhci/ring_buffer_controller.rs
index 6452a57..36387fc 100644
--- a/devices/src/usb/xhci/ring_buffer_controller.rs
+++ b/devices/src/usb/xhci/ring_buffer_controller.rs
@@ -106,7 +106,7 @@ where
             event_loop: event_loop.clone(),
             event: evt,
         });
-        let event_handler: Arc<EventHandler> = controller.clone();
+        let event_handler: Arc<dyn EventHandler> = controller.clone();
         event_loop
             .add_event(
                 &controller.event,
diff --git a/devices/src/usb/xhci/ring_buffer_stop_cb.rs b/devices/src/usb/xhci/ring_buffer_stop_cb.rs
index 5a8eae7..8608601 100644
--- a/devices/src/usb/xhci/ring_buffer_stop_cb.rs
+++ b/devices/src/usb/xhci/ring_buffer_stop_cb.rs
@@ -26,7 +26,7 @@ impl RingBufferStopCallback {
 }
 
 struct RingBufferStopCallbackInner {
-    callback: Box<FnMut() + Send>,
+    callback: Box<dyn FnMut() + Send>,
 }
 
 impl Drop for RingBufferStopCallbackInner {
@@ -38,7 +38,7 @@ impl Drop for RingBufferStopCallbackInner {
 /// Helper function to wrap up a closure with fail handle. The fail handle will be triggered if the
 /// closure returns an error.
 pub fn fallible_closure<E: std::fmt::Display, C: FnMut() -> Result<(), E> + 'static + Send>(
-    fail_handle: Arc<FailHandle>,
+    fail_handle: Arc<dyn FailHandle>,
     mut callback: C,
 ) -> impl FnMut() + 'static + Send {
     move || match callback() {
diff --git a/devices/src/usb/xhci/usb_hub.rs b/devices/src/usb/xhci/usb_hub.rs
index dd0a6d9..37c59fb 100644
--- a/devices/src/usb/xhci/usb_hub.rs
+++ b/devices/src/usb/xhci/usb_hub.rs
@@ -74,7 +74,7 @@ pub struct UsbPort {
     portsc: Register<u32>,
     usbsts: Register<u32>,
     interrupter: Arc<Mutex<Interrupter>>,
-    backend_device: Mutex<Option<Box<XhciBackendDevice>>>,
+    backend_device: Mutex<Option<Box<dyn XhciBackendDevice>>>,
 }
 
 impl UsbPort {
@@ -116,7 +116,7 @@ impl UsbPort {
     }
 
     /// Get current connected backend.
-    pub fn get_backend_device(&self) -> MutexGuard<Option<Box<XhciBackendDevice>>> {
+    pub fn get_backend_device(&self) -> MutexGuard<Option<Box<dyn XhciBackendDevice>>> {
         self.backend_device.lock()
     }
 
@@ -131,7 +131,10 @@ impl UsbPort {
         Ok(())
     }
 
-    fn attach(&self, device: Box<XhciBackendDevice>) -> std::result::Result<(), InterrupterError> {
+    fn attach(
+        &self,
+        device: Box<dyn XhciBackendDevice>,
+    ) -> std::result::Result<(), InterrupterError> {
         usb_debug!("A backend is connected to port {}", self.port_id);
         let mut locked = self.backend_device.lock();
         assert!(locked.is_none());
@@ -250,7 +253,7 @@ impl UsbHub {
     }
 
     /// Connect backend to next empty port.
-    pub fn connect_backend(&self, backend: Box<XhciBackendDevice>) -> Result<u8> {
+    pub fn connect_backend(&self, backend: Box<dyn XhciBackendDevice>) -> Result<u8> {
         usb_debug!("Trying to connect backend to hub");
         for port in &self.ports {
             if port.is_attached() {
diff --git a/devices/src/usb/xhci/xhci.rs b/devices/src/usb/xhci/xhci.rs
index b69397e..0ede18a 100644
--- a/devices/src/usb/xhci/xhci.rs
+++ b/devices/src/usb/xhci/xhci.rs
@@ -58,7 +58,7 @@ impl Display for Error {
 
 /// xHCI controller implementation.
 pub struct Xhci {
-    fail_handle: Arc<FailHandle>,
+    fail_handle: Arc<dyn FailHandle>,
     regs: XhciRegs,
     interrupter: Arc<Mutex<Interrupter>>,
     command_ring_controller: Arc<CommandRingController>,
@@ -75,7 +75,7 @@ pub struct Xhci {
 impl Xhci {
     /// Create a new xHCI controller.
     pub fn new(
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         mem: GuestMemory,
         device_provider: HostBackendDeviceProvider,
         irq_evt: EventFd,
diff --git a/devices/src/usb/xhci/xhci_backend_device_provider.rs b/devices/src/usb/xhci/xhci_backend_device_provider.rs
index 2c9d4bf..9f186ec 100644
--- a/devices/src/usb/xhci/xhci_backend_device_provider.rs
+++ b/devices/src/usb/xhci/xhci_backend_device_provider.rs
@@ -12,7 +12,7 @@ pub trait XhciBackendDeviceProvider: Send {
     /// Start the provider on EventLoop.
     fn start(
         &mut self,
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
         event_loop: Arc<EventLoop>,
         hub: Arc<UsbHub>,
     ) -> std::result::Result<(), ()>;
diff --git a/devices/src/usb/xhci/xhci_controller.rs b/devices/src/usb/xhci/xhci_controller.rs
index f920704..2c8ba58 100644
--- a/devices/src/usb/xhci/xhci_controller.rs
+++ b/devices/src/usb/xhci/xhci_controller.rs
@@ -87,7 +87,7 @@ enum XhciControllerState {
         // Xhci init could fail.
         #[allow(dead_code)]
         xhci: Option<Arc<Xhci>>,
-        fail_handle: Arc<FailHandle>,
+        fail_handle: Arc<dyn FailHandle>,
     },
 }
 
@@ -131,7 +131,7 @@ impl XhciController {
                 irq_resample_evt,
             } => {
                 let (mmio, regs) = init_xhci_mmio_space_and_regs();
-                let fail_handle: Arc<FailHandle> = Arc::new(XhciFailHandle::new(&regs));
+                let fail_handle: Arc<dyn FailHandle> = Arc::new(XhciFailHandle::new(&regs));
                 let xhci = match Xhci::new(
                     fail_handle.clone(),
                     self.mem.clone(),
diff --git a/devices/src/usb/xhci/xhci_transfer.rs b/devices/src/usb/xhci/xhci_transfer.rs
index 76fecdc..76454af 100644
--- a/devices/src/usb/xhci/xhci_transfer.rs
+++ b/devices/src/usb/xhci/xhci_transfer.rs
@@ -66,7 +66,7 @@ pub enum XhciTransferState {
     /// When transfer is submitted, it will contain a transfer callback, which should be invoked
     /// when the transfer is cancelled.
     Submitted {
-        cancel_callback: Box<FnMut() + Send>,
+        cancel_callback: Box<dyn FnMut() + Send>,
     },
     Cancelling,
     Cancelled,