From 46b8f38987b06a4572f4f3f52dcff4d26173bd16 Mon Sep 17 00:00:00 2001 From: Michael Zhao Date: Sun, 23 Aug 2020 15:44:57 +0800 Subject: [PATCH] arch: Fix AArch64 clippy warnings of arch crate Signed-off-by: Michael Zhao --- arch/src/aarch64/fdt.rs | 18 +++++++++--------- arch/src/aarch64/gic.rs | 16 ++++++++-------- arch/src/aarch64/gicv2.rs | 6 +++--- arch/src/aarch64/gicv3.rs | 9 ++++----- arch/src/aarch64/gicv3_its.rs | 8 ++++---- arch/src/aarch64/mod.rs | 7 ++++--- arch/src/aarch64/regs.rs | 2 +- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/arch/src/aarch64/fdt.rs b/arch/src/aarch64/fdt.rs index 4d89e9a59..fd01deb06 100644 --- a/arch/src/aarch64/fdt.rs +++ b/arch/src/aarch64/fdt.rs @@ -90,12 +90,12 @@ pub enum Error { type Result = result::Result; /// Creates the flattened device tree for this aarch64 VM. -pub fn create_fdt( +pub fn create_fdt( guest_mem: &GuestMemoryMmap, cmdline: &CStr, vcpu_mpidr: Vec, - device_info: &HashMap<(DeviceType, String), T>, - gic_device: &Box, + device_info: &HashMap<(DeviceType, String), T, S>, + gic_device: &dyn GICDevice, initrd: &Option, pci_space_address: &Option<(u64, u64)>, ) -> Result> { @@ -311,7 +311,7 @@ fn generate_prop64(cells: &[u64]) -> Vec { } // Following are the auxiliary function for creating the different nodes that we append to our FDT. -fn create_cpu_nodes(fdt: &mut Vec, vcpu_mpidr: &Vec) -> Result<()> { +fn create_cpu_nodes(fdt: &mut Vec, vcpu_mpidr: &[u64]) -> Result<()> { // See https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/arm/cpus.yaml. append_begin_node(fdt, "cpus")?; // As per documentation, on ARM v8 64-bit systems value should be set to 2. @@ -319,7 +319,7 @@ fn create_cpu_nodes(fdt: &mut Vec, vcpu_mpidr: &Vec) -> Result<()> { append_property_u32(fdt, "#size-cells", 0x0)?; let num_cpus = vcpu_mpidr.len(); - for cpu_index in 0..num_cpus { + for (cpu_index, mpidr) in vcpu_mpidr.iter().enumerate().take(num_cpus) { let cpu_name = format!("cpu@{:x}", cpu_index); append_begin_node(fdt, &cpu_name)?; append_property_string(fdt, "device_type", "cpu")?; @@ -330,7 +330,7 @@ fn create_cpu_nodes(fdt: &mut Vec, vcpu_mpidr: &Vec) -> Result<()> { } // Set the field to first 24 bits of the MPIDR - Multiprocessor Affinity Register. // See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0488c/BABHBJCI.html. - append_property_u64(fdt, "reg", vcpu_mpidr[cpu_index] & 0x7FFFFF)?; + append_property_u64(fdt, "reg", mpidr & 0x7FFFFF)?; append_end_node(fdt)?; } append_end_node(fdt)?; @@ -376,7 +376,7 @@ fn create_chosen_node( Ok(()) } -fn create_gic_node(fdt: &mut Vec, gic_device: &Box) -> Result<()> { +fn create_gic_node(fdt: &mut Vec, gic_device: &dyn GICDevice) -> Result<()> { let gic_reg_prop = generate_prop64(gic_device.device_properties()); append_begin_node(fdt, "intc")?; @@ -521,9 +521,9 @@ fn create_rtc_node( Ok(()) } -fn create_devices_node( +fn create_devices_node( fdt: &mut Vec, - dev_info: &HashMap<(DeviceType, String), T>, + dev_info: &HashMap<(DeviceType, String), T, S>, ) -> Result<()> { // Create one temp Vec to store all virtio devices let mut ordered_virtio_device: Vec<&T> = Vec::new(); diff --git a/arch/src/aarch64/gic.rs b/arch/src/aarch64/gic.rs index 601d6e893..a48fd39e4 100644 --- a/arch/src/aarch64/gic.rs +++ b/arch/src/aarch64/gic.rs @@ -71,7 +71,7 @@ pub mod kvm { /// Setup the device-specific attributes fn init_device_attributes( vm: &Arc, - gic_device: &Box, + gic_device: &dyn GICDevice, ) -> Result<()>; /// Initialize a GIC device @@ -95,10 +95,10 @@ pub mod kvm { flags: u32, ) -> Result<()> { let attr = kvm_bindings::kvm_device_attr { - group: group, - attr: attr, - addr: addr, - flags: flags, + group, + attr, + addr, + flags, }; device .set_device_attr(&attr) @@ -108,7 +108,7 @@ pub mod kvm { } /// Finalize the setup of a GIC device - fn finalize_device(gic_device: &Box) -> Result<()> { + fn finalize_device(gic_device: &dyn GICDevice) -> Result<()> { /* We need to tell the kernel how many irqs to support with this vgic. * See the `layout` module for details. */ @@ -142,9 +142,9 @@ pub mod kvm { let device = Self::create_device(vgic_fd, vcpu_count); - Self::init_device_attributes(vm, &device)?; + Self::init_device_attributes(vm, &*device)?; - Self::finalize_device(&device)?; + Self::finalize_device(&*device)?; Ok(device) } diff --git a/arch/src/aarch64/gicv2.rs b/arch/src/aarch64/gicv2.rs index e840fd3f5..1ca795f1a 100644 --- a/arch/src/aarch64/gicv2.rs +++ b/arch/src/aarch64/gicv2.rs @@ -84,20 +84,20 @@ pub mod kvm { vcpu_count: u64, ) -> Box { Box::new(KvmGICv2 { - device: device, + device, properties: [ KvmGICv2::get_dist_addr(), KvmGICv2::get_dist_size(), KvmGICv2::get_cpu_addr(), KvmGICv2::get_cpu_size(), ], - vcpu_count: vcpu_count, + vcpu_count, }) } fn init_device_attributes( _vm: &Arc, - gic_device: &Box, + gic_device: &dyn GICDevice, ) -> Result<()> { /* Setting up the distributor attribute. We are placing the GIC below 1GB so we need to substract the size of the distributor. */ diff --git a/arch/src/aarch64/gicv3.rs b/arch/src/aarch64/gicv3.rs index f7673eef7..c7a36db9c 100644 --- a/arch/src/aarch64/gicv3.rs +++ b/arch/src/aarch64/gicv3.rs @@ -84,20 +84,20 @@ pub mod kvm { vcpu_count: u64, ) -> Box { Box::new(KvmGICv3 { - device: device, + device, properties: [ KvmGICv3::get_dist_addr(), KvmGICv3::get_dist_size(), KvmGICv3::get_redists_addr(vcpu_count), KvmGICv3::get_redists_size(vcpu_count), ], - vcpu_count: vcpu_count, + vcpu_count, }) } fn init_device_attributes( _vm: &Arc, - gic_device: &Box, + gic_device: &dyn GICDevice, ) -> Result<()> { /* Setting up the distributor attribute. We are placing the GIC below 1GB so we need to substract the size of the distributor. @@ -117,8 +117,7 @@ pub mod kvm { gic_device.device(), kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR, u64::from(kvm_bindings::KVM_VGIC_V3_ADDR_TYPE_REDIST), - &KvmGICv3::get_redists_addr(u64::from(gic_device.vcpu_count())) as *const u64 - as u64, + &KvmGICv3::get_redists_addr(gic_device.vcpu_count()) as *const u64 as u64, 0, )?; diff --git a/arch/src/aarch64/gicv3_its.rs b/arch/src/aarch64/gicv3_its.rs index 9967433fd..2163e5d4e 100644 --- a/arch/src/aarch64/gicv3_its.rs +++ b/arch/src/aarch64/gicv3_its.rs @@ -80,7 +80,7 @@ pub mod kvm { vcpu_count: u64, ) -> Box { Box::new(KvmGICv3ITS { - device: device, + device, gic_properties: [ KvmGICv3::get_dist_addr(), KvmGICv3::get_dist_size(), @@ -91,13 +91,13 @@ pub mod kvm { KvmGICv3ITS::get_msi_addr(vcpu_count), KvmGICv3ITS::get_msi_size(), ], - vcpu_count: vcpu_count, + vcpu_count, }) } fn init_device_attributes( vm: &Arc, - gic_device: &Box, + gic_device: &dyn GICDevice, ) -> Result<()> { KvmGICv3::init_device_attributes(vm, gic_device)?; @@ -115,7 +115,7 @@ pub mod kvm { &its_fd, kvm_bindings::KVM_DEV_ARM_VGIC_GRP_ADDR, u64::from(kvm_bindings::KVM_VGIC_ITS_ADDR_TYPE), - &KvmGICv3ITS::get_msi_addr(u64::from(gic_device.vcpu_count())) as *const u64 as u64, + &KvmGICv3ITS::get_msi_addr(gic_device.vcpu_count()) as *const u64 as u64, 0, )?; diff --git a/arch/src/aarch64/mod.rs b/arch/src/aarch64/mod.rs index 8d42cdc38..ab2f848b3 100644 --- a/arch/src/aarch64/mod.rs +++ b/arch/src/aarch64/mod.rs @@ -136,13 +136,14 @@ pub fn arch_memory_regions(size: GuestUsize) -> Vec<(GuestAddress, usize, Region /// /// * `guest_mem` - The memory to be used by the guest. /// * `num_cpus` - Number of virtual CPUs the guest will have. -pub fn configure_system( +#[allow(clippy::too_many_arguments)] +pub fn configure_system( vm: &Arc, guest_mem: &GuestMemoryMmap, cmdline_cstring: &CStr, vcpu_count: u64, vcpu_mpidr: Vec, - device_info: &HashMap<(DeviceType, String), T>, + device_info: &HashMap<(DeviceType, String), T, S>, initrd: &Option, pci_space_address: &Option<(u64, u64)>, ) -> super::Result<()> { @@ -157,7 +158,7 @@ pub fn configure_system( cmdline_cstring, vcpu_mpidr, device_info, - &gic_device, + &*gic_device, initrd, pci_space_address, ) diff --git a/arch/src/aarch64/regs.rs b/arch/src/aarch64/regs.rs index 2abfada06..4847aa1cb 100644 --- a/arch/src/aarch64/regs.rs +++ b/arch/src/aarch64/regs.rs @@ -52,7 +52,7 @@ const PSTATE_FAULT_BITS_64: u64 = PSR_MODE_EL1h | PSR_A_BIT | PSR_F_BIT | PSR_I_ // we're just doing pointer math on it, so in theory, it should safe. macro_rules! offset__of { ($str:ty, $field:ident) => { - unsafe { &(*(0 as *const $str)).$field as *const _ as usize } + unsafe { &(*std::ptr::null::()).$field as *const _ as usize } }; }