fmt: refactor in pci & balloon

1. merge hashmap get logic according to Xuewei suggestion.

2. do cargo fmt

Signed-off-by: Chao Wu <chaowu@linux.alibaba.com>
This commit is contained in:
Chao Wu
2023-11-17 16:35:49 +08:00
parent baf3db9e6e
commit ee55897827
2 changed files with 8 additions and 6 deletions

View File

@@ -299,8 +299,7 @@ pub fn setup_mptable<M: GuestMemory>(
// Patch irq routing entry for mptable if it is registered
// as PCI legacy irq.
if let Some(irq_device) = pci_legacy_irqs {
if irq_device.contains_key(&i) {
let device_id = irq_device.get(&i).unwrap();
if let Some(device_id) = irq_device.get(&i) {
mpc_intsrc.0.srcbus = BUS_ID_PCI;
mpc_intsrc.0.srcbusirq = device_id << 2;
}

View File

@@ -675,11 +675,14 @@ where
error!("Failed to write config space");
return Err(ConfigError::InvalidOffset(offset));
};
let Some(dst) = start.checked_add(data.len())
.and_then(|end| config_slice.get_mut(start..end)) else
{
let Some(dst) = start
.checked_add(data.len())
.and_then(|end| config_slice.get_mut(start..end))
else {
error!("Failed to write config space");
return Err(ConfigError::InvalidOffsetPlusDataLen(offset + data.len() as u64));
return Err(ConfigError::InvalidOffsetPlusDataLen(
offset + data.len() as u64,
));
};
dst.copy_from_slice(data);
Ok(())