fix: add try_mem() to PciBar, fix virtio-core caller

Added try_mem() returning Option<(usize, usize)> for non-panicking
memory BAR access. Fixed virtio-core/probe.rs to use .ok_or() instead
of .map_err() to match the Option return type.
This commit is contained in:
Red Bear OS
2026-07-12 02:34:09 +03:00
parent be2d7503c9
commit bf9989b7c0
3 changed files with 24 additions and 1 deletions
+13
View File
@@ -52,4 +52,17 @@ impl PciBar {
PciBar::None => panic!("expected BAR to exist"),
}
}
pub fn try_mem(&self) -> Option<(usize, usize)> {
match *self {
PciBar::Memory32 { addr, size } => Some((addr as usize, size as usize)),
PciBar::Memory64 { addr, size } => Some((
addr.try_into()
.expect("conversion from 64bit BAR to usize failed"),
size.try_into()
.expect("conversion from 64bit BAR size to usize failed"),
)),
_ => None,
}
}
}