From d449983495db036307e6f0acc60bfebdc1b046c9 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 16 Apr 2026 21:01:25 +0100 Subject: [PATCH] vmm: Be consistent with PCI bus reservation nomenclature Our bus slots are now Reserved/Allocated/Free so change the method to free it to free_device_id() and update error. Also update to take u8 to match the other methods. Signed-off-by: Rob Bradford --- pci/src/bus.rs | 15 +++++++++++---- vmm/src/device_manager.rs | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pci/src/bus.rs b/pci/src/bus.rs index 4e52ebc9b..89efd2ed6 100644 --- a/pci/src/bus.rs +++ b/pci/src/bus.rs @@ -243,12 +243,19 @@ impl PciBus { } } - pub fn put_device_id(&mut self, id: usize) -> Result<()> { - if id < NUM_DEVICE_IDS as usize { - self.device_ids[id] = DeviceIdState::Free; + /// Frees a PCI device ID on the bus. + /// + /// - `id`: ID to free on the bus. + /// + /// ## Errors + /// * Returns [`PciRootError::InvalidPciDeviceSlot`] if the slot + /// exceeds [`NUM_DEVICE_IDS`]. + pub fn free_device_id(&mut self, id: u8) -> Result<()> { + if id < NUM_DEVICE_IDS { + self.device_ids[id as usize] = DeviceIdState::Free; Ok(()) } else { - Err(PciRootError::InvalidPciDeviceSlot(id)) + Err(PciRootError::InvalidPciDeviceSlot(id as usize)) } } } diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 6c52026e1..9f65784ec 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -500,9 +500,9 @@ pub enum DeviceManagerError { #[error("Could not reserve the PCI device ID")] ReservePciDeviceId(#[source] pci::PciRootError), - /// Could not give the PCI device ID back. - #[error("Could not give the PCI device ID back")] - PutPciDeviceId(#[source] pci::PciRootError), + /// Could not free the PCI device ID. + #[error("Could not free PCI device ID")] + FreePciDeviceId(#[source] pci::PciRootError), /// No disk path was specified when one was expected #[error("No disk path was specified when one was expected")] @@ -4892,8 +4892,8 @@ impl DeviceManager { .pci_bus .lock() .unwrap() - .put_device_id(device_id as usize) - .map_err(DeviceManagerError::PutPciDeviceId)?; + .free_device_id(device_id) + .map_err(DeviceManagerError::FreePciDeviceId)?; let (pci_device_handle, id) = { // Remove the device from the device tree along with its children.