Skip to content

Commit 68912ef

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 <[email protected]>
1 parent 8886cb4 commit 68912ef

File tree

1 file changed

+2
-4
lines changed
  • src/vmm/src/device_manager

1 file changed

+2
-4
lines changed

src/vmm/src/device_manager/mod.rs

Lines changed: 2 additions & 4 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
}
@@ -468,7 +466,7 @@ impl<'a> Persist<'a> for DeviceManager {
468466
fn restore(
469467
constructor_args: Self::ConstructorArgs,
470468
state: &Self::State,
471-
) -> Result<Self, Self::Error> {
469+
) -> std::result::Result<Self, Self::Error> {
472470
// Setup legacy devices in case of x86
473471
#[cfg(target_arch = "x86_64")]
474472
let legacy_devices = Self::create_legacy_devices(

0 commit comments

Comments
 (0)