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:
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user