Skip to content

Commit ec964aa

Browse files
committed
refactor: assert device downcasting in device manager
When we get a type erased device from a underlying device storage we expect that it will always be of the type we requested with T::const_device_type(). If it is not true, we have an internal bug. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent a53e331 commit ec964aa

File tree

1 file changed

+1
-3
lines changed
  • src/vmm/src/device_manager

1 file changed

+1
-3
lines changed

src/vmm/src/device_manager/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ pub enum AttachDeviceError {
8787
#[derive(Debug, thiserror::Error, displaydoc::Display)]
8888
/// Error while searching for a VirtIO device
8989
pub enum FindDeviceError {
90-
/// Device type is invalid
91-
InvalidDeviceType,
9290
/// Device not found
9391
DeviceNotFound,
9492
}
@@ -385,7 +383,7 @@ impl DeviceManager {
385383
Ok(f(dev
386384
.as_mut_any()
387385
.downcast_mut::<T>()
388-
.ok_or(FindDeviceError::InvalidDeviceType)?))
386+
.expect("Invalid device for a given device type")))
389387
} else {
390388
Err(FindDeviceError::DeviceNotFound)
391389
}

0 commit comments

Comments
 (0)