From 3a63143f33f00530cc6cce3c622f82e1919f2e4a Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Fri, 30 Jun 2023 13:51:41 -0700 Subject: [PATCH] misc: Address clippy beta issues Signed-off-by: Bo Chen --- qcow/src/qcow_raw_file.rs | 4 ++-- tpm/src/emulator.rs | 6 +----- vhdx/src/vhdx_metadata.rs | 6 +----- virtio-devices/src/vhost_user/fs.rs | 2 +- vm-device/src/bus.rs | 3 +-- vmm/src/cpu.rs | 2 +- vmm/src/memory_manager.rs | 2 +- vmm/src/vm.rs | 2 +- 8 files changed, 9 insertions(+), 18 deletions(-) diff --git a/qcow/src/qcow_raw_file.rs b/qcow/src/qcow_raw_file.rs index 2c56cef23..6cedaf3ab 100644 --- a/qcow/src/qcow_raw_file.rs +++ b/qcow/src/qcow_raw_file.rs @@ -66,7 +66,7 @@ impl QcowRawFile { non_zero_flags: u64, ) -> io::Result<()> { self.file.seek(SeekFrom::Start(offset))?; - let mut buffer = BufWriter::with_capacity(table.len() * size_of::(), &mut self.file); + let mut buffer = BufWriter::with_capacity(std::mem::size_of_val(table), &mut self.file); for addr in table { let val = if *addr == 0 { 0 @@ -91,7 +91,7 @@ impl QcowRawFile { /// Writes a refcount block to the file. pub fn write_refcount_block(&mut self, offset: u64, table: &[u16]) -> io::Result<()> { self.file.seek(SeekFrom::Start(offset))?; - let mut buffer = BufWriter::with_capacity(table.len() * size_of::(), &mut self.file); + let mut buffer = BufWriter::with_capacity(std::mem::size_of_val(table), &mut self.file); for count in table { buffer.write_u16::(*count)?; } diff --git a/tpm/src/emulator.rs b/tpm/src/emulator.rs index 86422de9e..33d4a4a62 100644 --- a/tpm/src/emulator.rs +++ b/tpm/src/emulator.rs @@ -309,11 +309,7 @@ impl Emulator { } self.established_flag_cached = true; - if est.resp.bit != 0 { - self.established_flag = false; - } else { - self.established_flag = true; - } + self.established_flag = est.resp.bit == 0; self.established_flag } diff --git a/vhdx/src/vhdx_metadata.rs b/vhdx/src/vhdx_metadata.rs index 6a5602dbc..20a56add7 100644 --- a/vhdx/src/vhdx_metadata.rs +++ b/vhdx/src/vhdx_metadata.rs @@ -145,11 +145,7 @@ impl DiskSpec { let bits = f .read_u32::() .map_err(VhdxMetadataError::ReadMetadata)?; - if bits & BLOCK_HAS_PARENT != 0 { - disk_spec.has_parent = true; - } else { - disk_spec.has_parent = false; - } + disk_spec.has_parent = bits & BLOCK_HAS_PARENT != 0; metadata_presence |= METADATA_FILE_PARAMETER_PRESENT; } else if metadata_entry.item_id diff --git a/virtio-devices/src/vhost_user/fs.rs b/virtio-devices/src/vhost_user/fs.rs index 58ef70dc9..517a54913 100644 --- a/virtio-devices/src/vhost_user/fs.rs +++ b/virtio-devices/src/vhost_user/fs.rs @@ -605,7 +605,7 @@ impl VirtioDevice for Fs { &mut self, shm_regions: VirtioSharedMemoryList, ) -> std::result::Result<(), crate::Error> { - if let Some(mut cache) = self.cache.as_mut() { + if let Some(cache) = self.cache.as_mut() { cache.0 = shm_regions; Ok(()) } else { diff --git a/vm-device/src/bus.rs b/vm-device/src/bus.rs index 6e581c9a9..bf377154d 100644 --- a/vm-device/src/bus.rs +++ b/vm-device/src/bus.rs @@ -110,8 +110,7 @@ impl Bus { let devices = self.devices.read().unwrap(); let (range, dev) = devices .range(..=BusRange { base: addr, len: 1 }) - .rev() - .next()?; + .next_back()?; dev.upgrade().map(|d| (*range, d.clone())) } diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 5e0f97947..dce0f4006 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -1124,7 +1124,7 @@ impl CpuManager { fn remove_vcpu(&mut self, cpu_id: u8) -> Result<()> { info!("Removing vCPU: cpu_id = {}", cpu_id); - let mut state = &mut self.vcpu_states[usize::from(cpu_id)]; + let state = &mut self.vcpu_states[usize::from(cpu_id)]; state.kill.store(true, Ordering::SeqCst); state.signal_thread(); state.join_thread()?; diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index fbb08d7c1..7a164faed 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -1591,7 +1591,7 @@ impl MemoryManager { .ok_or(Error::MemoryRangeAllocation)?; // Update the slot so that it can be queried via the I/O port - let mut slot = &mut self.hotplug_slots[self.next_hotplug_slot]; + let slot = &mut self.hotplug_slots[self.next_hotplug_slot]; slot.active = true; slot.inserting = true; slot.base = region.start_addr().0; diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 683946f5f..609f6d0ca 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -1258,7 +1258,7 @@ impl Vm { .resize(desired_memory) .map_err(Error::MemoryManager)?; - let mut memory_config = &mut self.config.lock().unwrap().memory; + let memory_config = &mut self.config.lock().unwrap().memory; if let Some(new_region) = &new_region { self.device_manager