From 7aae97226371042bd5a4a10cceb2dcb13a025202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20Yi=C4=9Fit=20=C5=9Eahin?= Date: Sun, 28 Sep 2025 22:35:53 +0300 Subject: [PATCH] fix(pci): ignore incompatible capabilities instead of crashing It is possible for PCI devices to offer multiple capabilities of the same type that are offered through different kinds of BARs (e.g. IO or memory), so it is possible to encounter an incompatible capability but still function with an alternative. --- src/drivers/virtio/transport/pci.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/drivers/virtio/transport/pci.rs b/src/drivers/virtio/transport/pci.rs index 2f250bd525..53d3a3728d 100644 --- a/src/drivers/virtio/transport/pci.rs +++ b/src/drivers/virtio/transport/pci.rs @@ -690,14 +690,15 @@ fn read_caps(device: &PciDevice) -> Result, PciErro }) .map(|addr| CapData::read(addr, device.access()).unwrap()) .filter(|cap| cap.cfg_type != CapCfgType::Pci) - .map(|cap| { + .flat_map(|cap| { let slot = cap.bar; - let (addr, size) = device.memory_map_bar(slot, true).unwrap(); - PciCap { - bar: VirtioPciBar::new(slot, addr.as_u64(), size.try_into().unwrap()), - dev_id: device_id, - cap, - } + device + .memory_map_bar(slot, true) + .map(|(addr, size)| PciCap { + bar: VirtioPciBar::new(slot, addr.as_u64(), size.try_into().unwrap()), + dev_id: device_id, + cap, + }) }) .collect::>();