pci, devices, virtio-devices, vmm: Refactor allocate_bars

Refactor PciDevice::allocate_bars trait and all implementations
to take &mut SystemAllocator instead of &Arc<Mutex<SystemAllocator>>,
removing double indirection.

The caller in device_manager.rs now acquires the lock before
calling allocate_bars.

Signed-off-by: Chinmoy <daschinmoyy21@gmail.com>
This commit is contained in:
Chinmoy
2026-02-16 22:31:30 +05:30
committed by Rob Bradford
parent ef9133a3ee
commit d0b253472d
8 changed files with 12 additions and 14 deletions
+2 -4
View File
@@ -602,7 +602,7 @@ impl VfioCommon {
#[allow(unused_variables)]
pub(crate) fn allocate_bars(
&mut self,
allocator: &Arc<Mutex<SystemAllocator>>,
allocator: &mut SystemAllocator,
mmio32_allocator: &mut AddressAllocator,
mmio64_allocator: &mut AddressAllocator,
resources: Option<&[Resource]>,
@@ -741,8 +741,6 @@ impl VfioCommon {
PciBarRegionType::IoRegion => {
// The address needs to be 4 bytes aligned.
allocator
.lock()
.unwrap()
.allocate_io_addresses(restored_bar_addr, region_size, Some(0x4))
.ok_or(PciDeviceError::IoAllocationFailed(region_size))?
}
@@ -1852,7 +1850,7 @@ const PCI_ROM_EXP_BAR_INDEX: usize = 12;
impl PciDevice for VfioPciDevice {
fn allocate_bars(
&mut self,
allocator: &Arc<Mutex<SystemAllocator>>,
allocator: &mut SystemAllocator,
mmio32_allocator: &mut AddressAllocator,
mmio64_allocator: &mut AddressAllocator,
resources: Option<Vec<Resource>>,