From bf9989b7c05b6476d0fb81af7b0ef1c41a40c026 Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Sun, 12 Jul 2026 02:34:09 +0300 Subject: [PATCH] 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. --- Cargo.lock | 10 ++++++++++ drivers/pcid/src/driver_interface/bar.rs | 13 +++++++++++++ drivers/virtio-core/src/probe.rs | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 81b485e250..0f9809710a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/drivers/pcid/src/driver_interface/bar.rs b/drivers/pcid/src/driver_interface/bar.rs index b2c1d35bbd..03bce8474a 100644 --- a/drivers/pcid/src/driver_interface/bar.rs +++ b/drivers/pcid/src/driver_interface/bar.rs @@ -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, + } + } } diff --git a/drivers/virtio-core/src/probe.rs b/drivers/virtio-core/src/probe.rs index eaef1b96f4..bd656932af 100644 --- a/drivers/virtio-core/src/probe.rs +++ b/drivers/virtio-core/src/probe.rs @@ -57,7 +57,7 @@ pub fn probe_device(pcid_handle: &mut PciFunctionHandle) -> Result