diff --git a/arch/src/lib.rs b/arch/src/lib.rs index 6809f8558..ea01c3d1f 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -3,7 +3,7 @@ #![allow( clippy::unreadable_literal, - clippy::const_static_lifetime, + clippy::redundant_static_lifetimes, clippy::cast_lossless, clippy::transmute_ptr_to_ptr, clippy::cast_ptr_alignment diff --git a/arch_gen/src/x86/mod.rs b/arch_gen/src/x86/mod.rs index ee0b10ac3..fecca5bdd 100644 --- a/arch_gen/src/x86/mod.rs +++ b/arch_gen/src/x86/mod.rs @@ -10,7 +10,7 @@ #[allow(non_snake_case)] #[allow( clippy::unreadable_literal, - clippy::const_static_lifetime, + clippy::redundant_static_lifetimes, clippy::trivially_copy_pass_by_ref, clippy::useless_transmute, clippy::should_implement_trait, @@ -19,8 +19,8 @@ pub mod bootparam; #[allow(non_camel_case_types)] #[allow(non_upper_case_globals)] -#[allow(clippy::unreadable_literal, clippy::const_static_lifetime)] +#[allow(clippy::unreadable_literal, clippy::redundant_static_lifetimes)] pub mod mpspec; #[allow(non_upper_case_globals)] -#[allow(clippy::unreadable_literal, clippy::const_static_lifetime)] +#[allow(clippy::unreadable_literal, clippy::redundant_static_lifetimes)] pub mod msr_index; diff --git a/devices/src/bus.rs b/devices/src/bus.rs index 348bab5e2..b408b6360 100644 --- a/devices/src/bus.rs +++ b/devices/src/bus.rs @@ -77,7 +77,7 @@ impl PartialOrd for BusRange { /// only restriction is that no two devices can overlap in this address space. #[derive(Clone, Default)] pub struct Bus { - devices: BTreeMap>>, + devices: BTreeMap>>, } impl Bus { @@ -88,7 +88,7 @@ impl Bus { } } - fn first_before(&self, addr: u64) -> Option<(BusRange, &Mutex)> { + fn first_before(&self, addr: u64) -> Option<(BusRange, &Mutex)> { let (range, dev) = self .devices .range(..=BusRange { base: addr, len: 1 }) @@ -97,7 +97,7 @@ impl Bus { Some((*range, dev)) } - pub fn resolve(&self, addr: u64) -> Option<(u64, u64, &Mutex)> { + pub fn resolve(&self, addr: u64) -> Option<(u64, u64, &Mutex)> { if let Some((range, dev)) = self.first_before(addr) { let offset = addr - range.base; if offset < range.len { @@ -108,7 +108,7 @@ impl Bus { } /// Puts the given device at the given address space. - pub fn insert(&mut self, device: Arc>, base: u64, len: u64) -> Result<()> { + pub fn insert(&mut self, device: Arc>, base: u64, len: u64) -> Result<()> { if len == 0 { return Err(Error::Overlap); } diff --git a/devices/src/ioapic.rs b/devices/src/ioapic.rs index f65ccaa86..5f89eaea5 100644 --- a/devices/src/ioapic.rs +++ b/devices/src/ioapic.rs @@ -188,7 +188,6 @@ impl BusDevice for Ioapic { IOWIN_OFF => self.ioapic_write(value), _ => { error!("IOAPIC: failed writing at offset {}", offset); - return; } } } diff --git a/devices/src/legacy/serial.rs b/devices/src/legacy/serial.rs index 63aa7e3d7..590b42a3d 100644 --- a/devices/src/legacy/serial.rs +++ b/devices/src/legacy/serial.rs @@ -55,7 +55,7 @@ const DEFAULT_BAUD_DIVISOR: u16 = 12; // 9600 bps pub struct Serial { interrupt_enable: u8, interrupt_identification: u8, - interrupt: Box, + interrupt: Box, line_control: u8, line_status: u8, modem_control: u8, @@ -63,11 +63,11 @@ pub struct Serial { scratch: u8, baud_divisor: u16, in_buffer: VecDeque, - out: Option>, + out: Option>, } impl Serial { - pub fn new(interrupt: Box, out: Option>) -> Serial { + pub fn new(interrupt: Box, out: Option>) -> Serial { Serial { interrupt_enable: 0, interrupt_identification: DEFAULT_INTERRUPT_IDENTIFICATION, @@ -84,12 +84,12 @@ impl Serial { } /// Constructs a Serial port ready for output. - pub fn new_out(interrupt: Box, out: Box) -> Serial { + pub fn new_out(interrupt: Box, out: Box) -> Serial { Self::new(interrupt, Some(out)) } /// Constructs a Serial port with no connected output. - pub fn new_sink(interrupt: Box) -> Serial { + pub fn new_sink(interrupt: Box) -> Serial { Self::new(interrupt, None) } diff --git a/pci/src/bus.rs b/pci/src/bus.rs index bc0c446fc..cc3c4b908 100644 --- a/pci/src/bus.rs +++ b/pci/src/bus.rs @@ -192,8 +192,8 @@ impl BusDevice for PciConfigIo { fn read(&mut self, _base: u64, offset: u64, data: &mut [u8]) { // `offset` is relative to 0xcf8 let value = match offset { - 0...3 => self.config_address, - 4...7 => self.config_space_read(), + 0..=3 => self.config_address, + 4..=7 => self.config_space_read(), _ => 0xffff_ffff, }; @@ -214,8 +214,8 @@ impl BusDevice for PciConfigIo { fn write(&mut self, _base: u64, offset: u64, data: &[u8]) { // `offset` is relative to 0xcf8 match offset { - o @ 0...3 => self.set_config_address(o, data), - o @ 4...7 => self.config_space_write(o - 4, data), + o @ 0..=3 => self.set_config_address(o, data), + o @ 4..=7 => self.config_space_write(o - 4, data), _ => (), }; } diff --git a/pci/src/device.rs b/pci/src/device.rs index 381133874..1baeb0edd 100755 --- a/pci/src/device.rs +++ b/pci/src/device.rs @@ -18,7 +18,7 @@ pub struct InterruptParameters<'a> { } pub type InterruptDelivery = - Box std::result::Result<(), std::io::Error> + Send + Sync>; + Box std::result::Result<(), std::io::Error> + Send + Sync>; #[derive(Debug)] pub enum Error { diff --git a/qcow/src/qcow.rs b/qcow/src/qcow.rs index 016c30513..887afcc5c 100755 --- a/qcow/src/qcow.rs +++ b/qcow/src/qcow.rs @@ -1087,10 +1087,10 @@ impl QcowFile { let max_valid_cluster_offset = self.refcounts.max_valid_cluster_offset(); if let Some(new_cluster) = self.raw_file.add_cluster_end(max_valid_cluster_offset)? { - return Ok(new_cluster); + Ok(new_cluster) } else { error!("No free clusters in get_new_cluster()"); - return Err(std::io::Error::from_raw_os_error(ENOSPC)); + Err(std::io::Error::from_raw_os_error(ENOSPC)) } } diff --git a/src/main.rs b/src/main.rs index b233d3913..c11c5933f 100755 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use std::sync::Mutex; use vmm::config; struct Logger { - output: Mutex>, + output: Mutex>, start: std::time::Instant, } @@ -195,7 +195,7 @@ fn main() { _ => LevelFilter::Trace, }; - let log_file: Box = + let log_file: Box = if let Some(file) = cmd_arguments.value_of("log-file") { Box::new( std::fs::File::create(std::path::Path::new(file)).expect("Error creating log file"), @@ -285,7 +285,7 @@ mod tests { struct Guest<'a> { tmp_dir: TempDir, - disk_config: &'a DiskConfig, + disk_config: &'a dyn DiskConfig, fw_path: String, network: GuestNetworkConfig, } @@ -549,7 +549,7 @@ mod tests { } impl<'a> Guest<'a> { - fn new_from_ip_range(disk_config: &'a mut DiskConfig, class: &str, id: u8) -> Self { + fn new_from_ip_range(disk_config: &'a mut dyn DiskConfig, class: &str, id: u8) -> Self { let tmp_dir = TempDir::new("ch").unwrap(); let mut workload_path = dirs::home_dir().unwrap(); @@ -576,7 +576,7 @@ mod tests { } } - fn new(disk_config: &'a mut DiskConfig) -> Self { + fn new(disk_config: &'a mut dyn DiskConfig) -> Self { let mut guard = NEXT_VM_ID.lock().unwrap(); let id = *guard; *guard = id + 1; @@ -767,8 +767,8 @@ mod tests { let mut bionic = BionicDiskConfig::new(); vec![ - &mut clear as &mut DiskConfig, - &mut bionic as &mut DiskConfig, + &mut clear as &mut dyn DiskConfig, + &mut bionic as &mut dyn DiskConfig, ] .iter_mut() .for_each(|disk_config| { diff --git a/vfio/src/vfio_pci.rs b/vfio/src/vfio_pci.rs index c391e2259..7444ff0c7 100644 --- a/vfio/src/vfio_pci.rs +++ b/vfio/src/vfio_pci.rs @@ -388,11 +388,9 @@ impl VfioPciDevice { ..Default::default() }; - unsafe { - entry.u.msi.address_lo = route.msi_vector.msg_addr_lo; - entry.u.msi.address_hi = route.msi_vector.msg_addr_hi; - entry.u.msi.data = route.msi_vector.msg_data; - }; + entry.u.msi.address_lo = route.msi_vector.msg_addr_lo; + entry.u.msi.address_hi = route.msi_vector.msg_addr_hi; + entry.u.msi.data = route.msi_vector.msg_data; entry_vec.push(entry); } diff --git a/vm-virtio/src/console.rs b/vm-virtio/src/console.rs index d91ae6529..abd6601b3 100755 --- a/vm-virtio/src/console.rs +++ b/vm-virtio/src/console.rs @@ -57,7 +57,7 @@ struct ConsoleEpollHandler { mem: GuestMemoryMmap, interrupt_cb: Arc, in_buffer: Arc>>, - out: Box, + out: Box, input_queue_evt: EventFd, output_queue_evt: EventFd, input_evt: EventFd, @@ -321,13 +321,13 @@ pub struct Console { acked_features: u64, config: Arc>, input: Arc, - out: Option>, + out: Option>, } impl Console { /// Create a new virtio console device that gets random data from /dev/urandom. pub fn new( - out: Option>, + out: Option>, cols: u16, rows: u16, ) -> io::Result<(Console, Arc)> { diff --git a/vm-virtio/src/device.rs b/vm-virtio/src/device.rs index b2291b08e..63041b6b4 100644 --- a/vm-virtio/src/device.rs +++ b/vm-virtio/src/device.rs @@ -17,7 +17,7 @@ pub enum VirtioInterruptType { } pub type VirtioInterrupt = Box< - Fn(&VirtioInterruptType, Option<&Queue>) -> std::result::Result<(), std::io::Error> + dyn Fn(&VirtioInterruptType, Option<&Queue>) -> std::result::Result<(), std::io::Error> + Send + Sync, >; diff --git a/vm-virtio/src/transport/pci_device.rs b/vm-virtio/src/transport/pci_device.rs index 3de05c0ac..8332818f8 100755 --- a/vm-virtio/src/transport/pci_device.rs +++ b/vm-virtio/src/transport/pci_device.rs @@ -223,7 +223,7 @@ pub struct VirtioPciDevice { msix_num: u16, // Virtio device reference and status - device: Box, + device: Box, device_activated: bool, // PCI interrupts. @@ -243,7 +243,11 @@ pub struct VirtioPciDevice { impl VirtioPciDevice { /// Constructs a new PCI transport for the given virtio device. - pub fn new(memory: GuestMemoryMmap, device: Box, msix_num: u16) -> Result { + pub fn new( + memory: GuestMemoryMmap, + device: Box, + msix_num: u16, + ) -> Result { let mut queue_evts = Vec::new(); for _ in device.queue_max_sizes().iter() { queue_evts.push(EventFd::new(EFD_NONBLOCK)?) @@ -267,15 +271,15 @@ impl VirtioPciDevice { let (class, subclass) = match VirtioDeviceType::from(device.device_type()) { VirtioDeviceType::TYPE_NET => ( PciClassCode::NetworkController, - &PciNetworkControllerSubclass::EthernetController as &PciSubclass, + &PciNetworkControllerSubclass::EthernetController as &dyn PciSubclass, ), VirtioDeviceType::TYPE_BLOCK => ( PciClassCode::MassStorage, - &PciMassStorageSubclass::MassStorage as &PciSubclass, + &PciMassStorageSubclass::MassStorage as &dyn PciSubclass, ), _ => ( PciClassCode::Other, - &PciVirtioSubclass::NonTransitionalBase as &PciSubclass, + &PciVirtioSubclass::NonTransitionalBase as &dyn PciSubclass, ), }; diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 3c88b2337..cc6c6d189 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -97,10 +97,10 @@ pub enum DebugIoPortRange { impl DebugIoPortRange { fn from_u8(value: u8) -> DebugIoPortRange { match value { - 0x00...0x1f => DebugIoPortRange::Firmware, - 0x20...0x3f => DebugIoPortRange::Bootloader, - 0x40...0x5f => DebugIoPortRange::Kernel, - 0x60...0x7f => DebugIoPortRange::Userspace, + 0x00..=0x1f => DebugIoPortRange::Firmware, + 0x20..=0x3f => DebugIoPortRange::Bootloader, + 0x40..=0x5f => DebugIoPortRange::Kernel, + 0x60..=0x7f => DebugIoPortRange::Userspace, _ => DebugIoPortRange::Custom, } } @@ -641,7 +641,7 @@ impl DeviceManager { ioapic: &ioapic, }; - let serial_writer: Option> = match vm_info.vm_cfg.serial.mode { + let serial_writer: Option> = match vm_info.vm_cfg.serial.mode { ConsoleOutputMode::File => Some(Box::new( File::create(vm_info.vm_cfg.serial.file.unwrap()) .map_err(DeviceManagerError::SerialOutputFileOpen)?, @@ -652,7 +652,7 @@ impl DeviceManager { let serial = if vm_info.vm_cfg.serial.mode != ConsoleOutputMode::Off { // Serial is tied to IRQ #4 let serial_irq = 4; - let interrupt: Box = if let Some(ioapic) = &ioapic { + let interrupt: Box = if let Some(ioapic) = &ioapic { Box::new(UserIoapicIrq::new(ioapic.clone(), serial_irq)) } else { let serial_evt = EventFd::new(EFD_NONBLOCK).map_err(DeviceManagerError::EventFd)?; @@ -681,7 +681,7 @@ impl DeviceManager { let pci_root = PciRoot::new(None); let mut pci = PciConfigIo::new(pci_root); - let console_writer: Option> = match vm_info.vm_cfg.console.mode { + let console_writer: Option> = match vm_info.vm_cfg.console.mode { ConsoleOutputMode::File => Some(Box::new( File::create(vm_info.vm_cfg.console.file.unwrap()) .map_err(DeviceManagerError::ConsoleOutputFileOpen)?, @@ -798,7 +798,7 @@ impl DeviceManager { let dev = vm_virtio::Block::new(raw_img, disk_cfg.path.to_path_buf(), false) .map_err(DeviceManagerError::CreateVirtioBlock)?; - Box::new(dev) as Box + Box::new(dev) as Box } ImageType::Qcow2 => { let qcow_img = QcowFile::from(raw_img) @@ -806,7 +806,7 @@ impl DeviceManager { let dev = vm_virtio::Block::new(qcow_img, disk_cfg.path.to_path_buf(), false) .map_err(DeviceManagerError::CreateVirtioBlock)?; - Box::new(dev) as Box + Box::new(dev) as Box } }; @@ -835,7 +835,7 @@ impl DeviceManager { // Add virtio-net if required if let Some(net_list_cfg) = &vm_info.vm_cfg.net { for net_cfg in net_list_cfg.iter() { - let mut virtio_net_device: vm_virtio::Net; + let virtio_net_device: vm_virtio::Net; if let Some(tap_if_name) = net_cfg.tap { let tap = Tap::open_named(tap_if_name).map_err(DeviceManagerError::OpenTap)?; @@ -1112,7 +1112,7 @@ impl DeviceManager { } fn add_virtio_pci_device( - virtio_device: Box, + virtio_device: Box, memory: GuestMemoryMmap, allocator: &mut SystemAllocator, vm_fd: &Arc,