From dcc646f5b10ec3861e2b3d9dcb8c00c2e58ea9ac Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 29 Jul 2021 11:15:10 +0200 Subject: [PATCH] clippy: Fix redundant allocations With the new beta version, clippy complains about redundant allocation when using Arc>, and suggests replacing it simply with Arc. Signed-off-by: Sebastien Boeuf --- devices/src/acpi.rs | 4 ++-- devices/src/gic.rs | 2 +- devices/src/ioapic.rs | 2 +- devices/src/legacy/gpio_pl061.rs | 6 +++--- devices/src/legacy/rtc_pl031.rs | 8 +++----- devices/src/legacy/serial.rs | 20 ++++++++++---------- devices/src/legacy/uart_pl011.rs | 8 ++++---- hypervisor/src/kvm/mod.rs | 4 ++-- hypervisor/src/mshv/mod.rs | 6 +++--- hypervisor/src/vm.rs | 2 +- pci/src/msi.rs | 4 ++-- pci/src/msix.rs | 4 ++-- pci/src/vfio.rs | 10 +++++----- virtio-devices/src/transport/pci_device.rs | 6 +++--- vm-device/src/interrupt/mod.rs | 5 ++--- vmm/src/cpu.rs | 6 +++--- vmm/src/interrupt.rs | 22 ++++++++-------------- vmm/src/vm.rs | 4 ++-- 18 files changed, 57 insertions(+), 66 deletions(-) diff --git a/devices/src/acpi.rs b/devices/src/acpi.rs index 9f7603e35..e11449e2f 100644 --- a/devices/src/acpi.rs +++ b/devices/src/acpi.rs @@ -62,7 +62,7 @@ impl BusDevice for AcpiShutdownDevice { /// A device for handling ACPI GED event generation pub struct AcpiGedDevice { - interrupt: Arc>, + interrupt: Arc, notification_type: AcpiNotificationFlags, ged_irq: u32, address: GuestAddress, @@ -70,7 +70,7 @@ pub struct AcpiGedDevice { impl AcpiGedDevice { pub fn new( - interrupt: Arc>, + interrupt: Arc, ged_irq: u32, address: GuestAddress, ) -> AcpiGedDevice { diff --git a/devices/src/gic.rs b/devices/src/gic.rs index 8621497a4..f3d5bd5f6 100644 --- a/devices/src/gic.rs +++ b/devices/src/gic.rs @@ -26,7 +26,7 @@ pub const IRQ_LEGACY_COUNT: usize = 32; // 1. Move Gic*.rs from arch/ folder here. // 2. Move this file and ioapic.rs to arch/, as they are architecture specific. pub struct Gic { - interrupt_source_group: Arc>, + interrupt_source_group: Arc, gic_device: Option>>>, } diff --git a/devices/src/ioapic.rs b/devices/src/ioapic.rs index 52a942b3a..881c261e2 100644 --- a/devices/src/ioapic.rs +++ b/devices/src/ioapic.rs @@ -134,7 +134,7 @@ pub struct Ioapic { reg_entries: [RedirectionTableEntry; NUM_IOAPIC_PINS], used_entries: [bool; NUM_IOAPIC_PINS], apic_address: GuestAddress, - interrupt_source_group: Arc>, + interrupt_source_group: Arc, } #[derive(Versionize)] diff --git a/devices/src/legacy/gpio_pl061.rs b/devices/src/legacy/gpio_pl061.rs index 55d18c867..90a11323d 100644 --- a/devices/src/legacy/gpio_pl061.rs +++ b/devices/src/legacy/gpio_pl061.rs @@ -86,7 +86,7 @@ pub struct Gpio { // Mode Control Select Register afsel: u32, // GPIO irq_field - interrupt: Arc>, + interrupt: Arc, } #[derive(Versionize)] @@ -106,7 +106,7 @@ impl VersionMapped for GpioState {} impl Gpio { /// Constructs an PL061 GPIO device. - pub fn new(id: String, interrupt: Arc>) -> Self { + pub fn new(id: String, interrupt: Arc) -> Self { Self { id, data: 0, @@ -376,7 +376,7 @@ mod tests { let intr_evt = EventFd::new(libc::EFD_NONBLOCK).unwrap(); let mut gpio = Gpio::new( String::from(GPIO_NAME), - Arc::new(Box::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))), + Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())), ); let mut data = [0; 4]; diff --git a/devices/src/legacy/rtc_pl031.rs b/devices/src/legacy/rtc_pl031.rs index a6c0a63ce..73b3c4cf2 100644 --- a/devices/src/legacy/rtc_pl031.rs +++ b/devices/src/legacy/rtc_pl031.rs @@ -224,12 +224,12 @@ pub struct Rtc { load: u32, imsc: u32, ris: u32, - interrupt: Arc>, + interrupt: Arc, } impl Rtc { /// Constructs an AMBA PL031 RTC device. - pub fn new(interrupt: Arc>) -> Self { + pub fn new(interrupt: Arc) -> Self { Self { // This is used only for duration measuring purposes. previous_now: Instant::now(), @@ -450,9 +450,7 @@ mod tests { fn test_rtc_read_write_and_event() { let intr_evt = EventFd::new(libc::EFD_NONBLOCK).unwrap(); - let mut rtc = Rtc::new(Arc::new(Box::new(TestInterrupt::new( - intr_evt.try_clone().unwrap(), - )))); + let mut rtc = Rtc::new(Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))); let mut data = [0; 4]; // Read and write to the MR register. diff --git a/devices/src/legacy/serial.rs b/devices/src/legacy/serial.rs index 27b73766d..c6554c770 100644 --- a/devices/src/legacy/serial.rs +++ b/devices/src/legacy/serial.rs @@ -63,7 +63,7 @@ pub struct Serial { id: String, interrupt_enable: u8, interrupt_identification: u8, - interrupt: Arc>, + interrupt: Arc, line_control: u8, line_status: u8, modem_control: u8, @@ -91,7 +91,7 @@ impl VersionMapped for SerialState {} impl Serial { pub fn new( id: String, - interrupt: Arc>, + interrupt: Arc, out: Option>, ) -> Serial { Serial { @@ -113,14 +113,14 @@ impl Serial { /// Constructs a Serial port ready for output. pub fn new_out( id: String, - interrupt: Arc>, + interrupt: Arc, out: Box, ) -> Serial { Self::new(id, interrupt, Some(out)) } /// Constructs a Serial port with no connected output. - pub fn new_sink(id: String, interrupt: Arc>) -> Serial { + pub fn new_sink(id: String, interrupt: Arc) -> Serial { Self::new(id, interrupt, None) } @@ -370,7 +370,7 @@ mod tests { let serial_out = SharedBuffer::new(); let mut serial = Serial::new_out( String::from(SERIAL_NAME), - Arc::new(Box::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))), + Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())), Box::new(serial_out.clone()), ); @@ -390,7 +390,7 @@ mod tests { let serial_out = SharedBuffer::new(); let mut serial = Serial::new_out( String::from(SERIAL_NAME), - Arc::new(Box::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))), + Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())), Box::new(serial_out), ); @@ -427,7 +427,7 @@ mod tests { let intr_evt = EventFd::new(0).unwrap(); let mut serial = Serial::new_sink( String::from(SERIAL_NAME), - Arc::new(Box::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))), + Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())), ); // write 1 to the interrupt event fd, so that read doesn't block in case the event fd @@ -449,7 +449,7 @@ mod tests { let intr_evt = EventFd::new(0).unwrap(); let mut serial = Serial::new_sink( String::from(SERIAL_NAME), - Arc::new(Box::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))), + Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())), ); serial.write(0, LCR as u64, &[LCR_DLAB_BIT]); @@ -470,7 +470,7 @@ mod tests { let intr_evt = EventFd::new(0).unwrap(); let mut serial = Serial::new_sink( String::from(SERIAL_NAME), - Arc::new(Box::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))), + Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())), ); serial.write(0, MCR as u64, &[MCR_LOOP_BIT]); @@ -496,7 +496,7 @@ mod tests { let intr_evt = EventFd::new(0).unwrap(); let mut serial = Serial::new_sink( String::from(SERIAL_NAME), - Arc::new(Box::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))), + Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())), ); serial.write(0, SCR as u64, &[0x12]); diff --git a/devices/src/legacy/uart_pl011.rs b/devices/src/legacy/uart_pl011.rs index fe2fa4800..e4e2379c7 100644 --- a/devices/src/legacy/uart_pl011.rs +++ b/devices/src/legacy/uart_pl011.rs @@ -86,7 +86,7 @@ pub struct Pl011 { ifl: u32, read_count: u32, read_trigger: u32, - irq: Arc>, + irq: Arc, out: Option>, } @@ -114,7 +114,7 @@ impl Pl011 { /// Constructs an AMBA PL011 UART device. pub fn new( id: String, - irq: Arc>, + irq: Arc, out: Option>, ) -> Self { Self { @@ -440,7 +440,7 @@ mod tests { let pl011_out = SharedBuffer::new(); let mut pl011 = Pl011::new( String::from(SERIAL_NAME), - Arc::new(Box::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))), + Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())), Some(Box::new(pl011_out.clone())), ); @@ -460,7 +460,7 @@ mod tests { let pl011_out = SharedBuffer::new(); let mut pl011 = Pl011::new( String::from(SERIAL_NAME), - Arc::new(Box::new(TestInterrupt::new(intr_evt.try_clone().unwrap()))), + Arc::new(TestInterrupt::new(intr_evt.try_clone().unwrap())), Some(Box::new(pl011_out)), ); diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index a761bb649..9b865de2b 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -178,7 +178,7 @@ impl vm::Vm for KvmVm { fn create_vcpu( &self, id: u8, - vmmops: Option>>, + vmmops: Option>, ) -> vm::Result> { let vc = self .fd @@ -731,7 +731,7 @@ pub struct KvmVcpu { fd: VcpuFd, #[cfg(target_arch = "x86_64")] msrs: MsrEntries, - vmmops: Option>>, + vmmops: Option>, #[cfg(target_arch = "x86_64")] hyperv_synic: AtomicBool, } diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 9f82b8dbc..a9033e894 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -133,7 +133,7 @@ pub struct MshvVcpu { cpuid: CpuId, msrs: MsrEntries, hv_state: Arc>, // Mshv State - vmmops: Option>>, + vmmops: Option>, } /// Implementation of Vcpu trait for Microsoft Hypervisor @@ -680,7 +680,7 @@ pub struct MshvVm { msrs: MsrEntries, // Hypervisor State hv_state: Arc>, - vmmops: Option>>, + vmmops: Option>, } fn hv_state_init() -> Arc> { @@ -742,7 +742,7 @@ impl vm::Vm for MshvVm { fn create_vcpu( &self, id: u8, - vmmops: Option>>, + vmmops: Option>, ) -> vm::Result> { let vcpu_fd = self .fd diff --git a/hypervisor/src/vm.rs b/hypervisor/src/vm.rs index 11b1f7e45..11ab20944 100644 --- a/hypervisor/src/vm.rs +++ b/hypervisor/src/vm.rs @@ -228,7 +228,7 @@ pub trait Vm: Send + Sync { /// Unregister an event that will, when signaled, trigger the `gsi` IRQ. fn unregister_irqfd(&self, fd: &EventFd, gsi: u32) -> Result<()>; /// Creates a new KVM vCPU file descriptor and maps the memory corresponding - fn create_vcpu(&self, id: u8, vmmops: Option>>) -> Result>; + fn create_vcpu(&self, id: u8, vmmops: Option>) -> Result>; /// Registers an event to be signaled whenever a certain address is written to. fn register_ioevent( &self, diff --git a/pci/src/msi.rs b/pci/src/msi.rs index 20dac594a..bd2ec355f 100644 --- a/pci/src/msi.rs +++ b/pci/src/msi.rs @@ -159,11 +159,11 @@ impl MsiCap { pub struct MsiConfig { cap: MsiCap, - interrupt_source_group: Arc>, + interrupt_source_group: Arc, } impl MsiConfig { - pub fn new(msg_ctl: u16, interrupt_source_group: Arc>) -> Self { + pub fn new(msg_ctl: u16, interrupt_source_group: Arc) -> Self { let cap = MsiCap { msg_ctl, ..Default::default() diff --git a/pci/src/msix.rs b/pci/src/msix.rs index 16d11a3d2..008ca253f 100644 --- a/pci/src/msix.rs +++ b/pci/src/msix.rs @@ -74,7 +74,7 @@ pub struct MsixConfig { pub table_entries: Vec, pub pba_entries: Vec, pub devid: u32, - interrupt_source_group: Arc>, + interrupt_source_group: Arc, masked: bool, enabled: bool, } @@ -82,7 +82,7 @@ pub struct MsixConfig { impl MsixConfig { pub fn new( msix_vectors: u16, - interrupt_source_group: Arc>, + interrupt_source_group: Arc, devid: u32, ) -> Self { assert!(msix_vectors <= MAX_MSIX_VECTORS_PER_DEVICE); diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index 65019e173..6c2df80c4 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -89,14 +89,14 @@ enum InterruptUpdateAction { } struct VfioIntx { - interrupt_source_group: Arc>, + interrupt_source_group: Arc, enabled: bool, } struct VfioMsi { cfg: MsiConfig, cap_offset: u32, - interrupt_source_group: Arc>, + interrupt_source_group: Arc, } impl VfioMsi { @@ -123,7 +123,7 @@ struct VfioMsix { bar: MsixConfig, cap: MsixCap, cap_offset: u32, - interrupt_source_group: Arc>, + interrupt_source_group: Arc, } impl VfioMsix { @@ -309,7 +309,7 @@ impl VfioPciDevice { device: VfioDevice, container: Arc, msi_interrupt_manager: &Arc>, - legacy_interrupt_group: Option>>, + legacy_interrupt_group: Option>, iommu_attached: bool, ) -> Result { let device = Arc::new(device); @@ -438,7 +438,7 @@ impl VfioPciDevice { fn initialize_legacy_interrupt( &mut self, - legacy_interrupt_group: Option>>, + legacy_interrupt_group: Option>, ) -> Result<()> { if let Some(irq_info) = self.device.get_irq_info(VFIO_PCI_INTX_IRQ_INDEX) { if irq_info.count == 0 { diff --git a/virtio-devices/src/transport/pci_device.rs b/virtio-devices/src/transport/pci_device.rs index 12450b03c..5957e4d90 100644 --- a/virtio-devices/src/transport/pci_device.rs +++ b/virtio-devices/src/transport/pci_device.rs @@ -306,7 +306,7 @@ pub struct VirtioPciDevice { // PCI interrupts. interrupt_status: Arc, virtio_interrupt: Option>, - interrupt_source_group: Arc>, + interrupt_source_group: Arc, // virtio queues queues: Vec, @@ -722,14 +722,14 @@ impl VirtioTransport for VirtioPciDevice { pub struct VirtioInterruptMsix { msix_config: Arc>, config_vector: Arc, - interrupt_source_group: Arc>, + interrupt_source_group: Arc, } impl VirtioInterruptMsix { pub fn new( msix_config: Arc>, config_vector: Arc, - interrupt_source_group: Arc>, + interrupt_source_group: Arc, ) -> Self { VirtioInterruptMsix { msix_config, diff --git a/vm-device/src/interrupt/mod.rs b/vm-device/src/interrupt/mod.rs index 9f403d54c..b73821e31 100644 --- a/vm-device/src/interrupt/mod.rs +++ b/vm-device/src/interrupt/mod.rs @@ -136,8 +136,7 @@ pub trait InterruptManager: Send + Sync { /// * interrupt_type: type of interrupt source. /// * base: base Interrupt Source ID to be managed by the group object. /// * count: number of Interrupt Sources to be managed by the group object. - fn create_group(&self, config: Self::GroupConfig) - -> Result>>; + fn create_group(&self, config: Self::GroupConfig) -> Result>; /// Destroy an [InterruptSourceGroup](trait.InterruptSourceGroup.html) object created by /// [create_group()](trait.InterruptManager.html#tymethod.create_group). @@ -145,7 +144,7 @@ pub trait InterruptManager: Send + Sync { /// Assume the caller takes the responsibility to disable all interrupt sources of the group /// before calling destroy_group(). This assumption helps to simplify InterruptSourceGroup /// implementations. - fn destroy_group(&self, group: Arc>) -> Result<()>; + fn destroy_group(&self, group: Arc) -> Result<()>; } pub trait InterruptSourceGroup: Send + Sync { diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 892b7798e..de3c5b196 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -224,7 +224,7 @@ impl Vcpu { pub fn new( id: u8, vm: &Arc, - vmmops: Option>>, + vmmops: Option>, ) -> Result>> { let vcpu = vm .create_vcpu(id, vmmops) @@ -374,7 +374,7 @@ pub struct CpuManager { selected_cpu: u8, vcpus: Vec>>, seccomp_action: SeccompAction, - vmmops: Arc>, + vmmops: Arc, #[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, seccomp_action: SeccompAction, - vmmops: Arc>, + vmmops: Arc, #[cfg(feature = "tdx")] tdx_enabled: bool, #[cfg(feature = "acpi")] numa_nodes: &NumaNodes, ) -> Result>> { diff --git a/vmm/src/interrupt.rs b/vmm/src/interrupt.rs index d903ebd86..3b4c2f465 100644 --- a/vmm/src/interrupt.rs +++ b/vmm/src/interrupt.rs @@ -291,17 +291,14 @@ impl MsiInterruptManager { impl InterruptManager for LegacyUserspaceInterruptManager { type GroupConfig = LegacyIrqGroupConfig; - fn create_group( - &self, - config: Self::GroupConfig, - ) -> Result>> { - Ok(Arc::new(Box::new(LegacyUserspaceInterruptGroup::new( + fn create_group(&self, config: Self::GroupConfig) -> Result> { + Ok(Arc::new(LegacyUserspaceInterruptGroup::new( self.ioapic.clone(), config.irq as u32, - )))) + ))) } - fn destroy_group(&self, _group: Arc>) -> Result<()> { + fn destroy_group(&self, _group: Arc) -> Result<()> { Ok(()) } } @@ -309,10 +306,7 @@ impl InterruptManager for LegacyUserspaceInterruptManager { impl InterruptManager for MsiInterruptManager { type GroupConfig = MsiIrqGroupConfig; - fn create_group( - &self, - config: Self::GroupConfig, - ) -> Result>> { + fn create_group(&self, config: Self::GroupConfig) -> Result> { let mut allocator = self.allocator.lock().unwrap(); let mut irq_routes: HashMap = HashMap::with_capacity(config.count as usize); @@ -320,14 +314,14 @@ impl InterruptManager for MsiInterruptManager { 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>) -> Result<()> { + fn destroy_group(&self, _group: Arc) -> Result<()> { Ok(()) } } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 65811374e..58c8cb3ae 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -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> = Arc::new(Box::new(VmOps { + let vm_ops: Arc = 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")]