clippy: Fix redundant allocations

With the new beta version, clippy complains about redundant allocation
when using Arc<Box<dyn T>>, and suggests replacing it simply with
Arc<dyn T>.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2021-07-29 11:15:10 +02:00
parent 91bd4ee8cc
commit dcc646f5b1
18 changed files with 57 additions and 66 deletions

View File

@@ -224,7 +224,7 @@ impl Vcpu {
pub fn new(
id: u8,
vm: &Arc<dyn hypervisor::Vm>,
vmmops: Option<Arc<Box<dyn VmmOps>>>,
vmmops: Option<Arc<dyn VmmOps>>,
) -> Result<Arc<Mutex<Self>>> {
let vcpu = vm
.create_vcpu(id, vmmops)
@@ -374,7 +374,7 @@ pub struct CpuManager {
selected_cpu: u8,
vcpus: Vec<Arc<Mutex<Vcpu>>>,
seccomp_action: SeccompAction,
vmmops: Arc<Box<dyn VmmOps>>,
vmmops: Arc<dyn VmmOps>,
#[cfg(feature = "acpi")]
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
acpi_address: GuestAddress,
@@ -516,7 +516,7 @@ impl CpuManager {
reset_evt: EventFd,
hypervisor: Arc<dyn hypervisor::Hypervisor>,
seccomp_action: SeccompAction,
vmmops: Arc<Box<dyn VmmOps>>,
vmmops: Arc<dyn VmmOps>,
#[cfg(feature = "tdx")] tdx_enabled: bool,
#[cfg(feature = "acpi")] numa_nodes: &NumaNodes,
) -> Result<Arc<Mutex<CpuManager>>> {

View File

@@ -291,17 +291,14 @@ impl MsiInterruptManager<IrqRoutingEntry> {
impl InterruptManager for LegacyUserspaceInterruptManager {
type GroupConfig = LegacyIrqGroupConfig;
fn create_group(
&self,
config: Self::GroupConfig,
) -> Result<Arc<Box<dyn InterruptSourceGroup>>> {
Ok(Arc::new(Box::new(LegacyUserspaceInterruptGroup::new(
fn create_group(&self, config: Self::GroupConfig) -> Result<Arc<dyn InterruptSourceGroup>> {
Ok(Arc::new(LegacyUserspaceInterruptGroup::new(
self.ioapic.clone(),
config.irq as u32,
))))
)))
}
fn destroy_group(&self, _group: Arc<Box<dyn InterruptSourceGroup>>) -> Result<()> {
fn destroy_group(&self, _group: Arc<dyn InterruptSourceGroup>) -> Result<()> {
Ok(())
}
}
@@ -309,10 +306,7 @@ impl InterruptManager for LegacyUserspaceInterruptManager {
impl InterruptManager for MsiInterruptManager<IrqRoutingEntry> {
type GroupConfig = MsiIrqGroupConfig;
fn create_group(
&self,
config: Self::GroupConfig,
) -> Result<Arc<Box<dyn InterruptSourceGroup>>> {
fn create_group(&self, config: Self::GroupConfig) -> Result<Arc<dyn InterruptSourceGroup>> {
let mut allocator = self.allocator.lock().unwrap();
let mut irq_routes: HashMap<InterruptIndex, InterruptRoute> =
HashMap::with_capacity(config.count as usize);
@@ -320,14 +314,14 @@ impl InterruptManager for MsiInterruptManager<IrqRoutingEntry> {
irq_routes.insert(i, InterruptRoute::new(&mut allocator)?);
}
Ok(Arc::new(Box::new(MsiInterruptGroup::new(
Ok(Arc::new(MsiInterruptGroup::new(
self.vm.clone(),
self.gsi_msi_routes.clone(),
irq_routes,
))))
)))
}
fn destroy_group(&self, _group: Arc<Box<dyn InterruptSourceGroup>>) -> Result<()> {
fn destroy_group(&self, _group: Arc<dyn InterruptSourceGroup>) -> Result<()> {
Ok(())
}
}

View File

@@ -580,14 +580,14 @@ impl Vm {
let mmio_bus = Arc::clone(device_manager.lock().unwrap().mmio_bus());
// Create the VmOps structure, which implements the VmmOps trait.
// And send it to the hypervisor.
let vm_ops: Arc<Box<dyn VmmOps>> = Arc::new(Box::new(VmOps {
let vm_ops: Arc<dyn VmmOps> = Arc::new(VmOps {
memory,
#[cfg(target_arch = "x86_64")]
io_bus,
mmio_bus,
#[cfg(target_arch = "x86_64")]
timestamp: std::time::Instant::now(),
}));
});
let exit_evt_clone = exit_evt.try_clone().map_err(Error::EventFdClone)?;
#[cfg(feature = "tdx")]