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:
Generated
+10
@@ -1325,6 +1325,7 @@ dependencies = [
|
||||
"daemon",
|
||||
"driver-network",
|
||||
"libredox",
|
||||
"log",
|
||||
"pcid",
|
||||
"redox_event",
|
||||
"redox_syscall 0.9.0+rb0.3.1",
|
||||
@@ -2411,6 +2412,15 @@ dependencies = [
|
||||
"numtoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thermald"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.69"
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ pub fn probe_device(pcid_handle: &mut PciFunctionHandle) -> Result<Device, Error
|
||||
|
||||
let (addr, _) = pci_config.func.bars[capability.bar as usize]
|
||||
.try_mem()
|
||||
.map_err(|_| Error::Probe("BAR is not memory-mapped"))?;
|
||||
.ok_or(Error::Probe("BAR is not memory-mapped"))?;
|
||||
|
||||
let address = unsafe {
|
||||
let addr = addr + capability.offset as usize;
|
||||
|
||||
Reference in New Issue
Block a user