diff options
-rw-r--r-- | aarch64/src/fdt.rs | 2 | ||||
-rw-r--r-- | crosvm_plugin/src/lib.rs | 6 | ||||
-rw-r--r-- | devices/src/utils/event_loop.rs | 2 | ||||
-rw-r--r-- | devices/src/virtio/virtio_pci_device.rs | 2 | ||||
-rw-r--r-- | devices/src/virtio/wl.rs | 6 | ||||
-rw-r--r-- | gpu_renderer/src/command_buffer.rs | 2 | ||||
-rw-r--r-- | gpu_renderer/src/lib.rs | 2 | ||||
-rw-r--r-- | qcow/src/qcow.rs | 6 | ||||
-rw-r--r-- | qcow/src/qcow_raw_file.rs | 2 | ||||
-rw-r--r-- | src/plugin/mod.rs | 2 | ||||
-rw-r--r-- | src/plugin/process.rs | 10 | ||||
-rw-r--r-- | src/plugin/vcpu.rs | 2 | ||||
-rw-r--r-- | sys_util/src/affinity.rs | 2 | ||||
-rw-r--r-- | sys_util/src/guest_memory.rs | 4 | ||||
-rw-r--r-- | sys_util/src/net.rs | 2 | ||||
-rw-r--r-- | sys_util/src/poll.rs | 9 | ||||
-rw-r--r-- | sys_util/src/write_zeroes.rs | 20 | ||||
-rw-r--r-- | x86_64/src/cpuid.rs | 2 | ||||
-rw-r--r-- | x86_64/src/mptable.rs | 2 |
19 files changed, 46 insertions, 39 deletions
diff --git a/aarch64/src/fdt.rs b/aarch64/src/fdt.rs index 98cadc4..3b0126f 100644 --- a/aarch64/src/fdt.rs +++ b/aarch64/src/fdt.rs @@ -114,7 +114,7 @@ fn create_timer_node(fdt: &mut Vec<u8>, num_cpus: u32) -> Result<()> { (((1 << num_cpus) - 1) << GIC_FDT_IRQ_PPI_CPU_SHIFT) & GIC_FDT_IRQ_PPI_CPU_MASK; let mut timer_reg_cells = Vec::new(); - for &irq in irqs.iter() { + for &irq in &irqs { timer_reg_cells.push(GIC_FDT_IRQ_TYPE_PPI); timer_reg_cells.push(irq); timer_reg_cells.push(cpu_mask | IRQ_TYPE_LEVEL_LOW); diff --git a/crosvm_plugin/src/lib.rs b/crosvm_plugin/src/lib.rs index 31684b3..eb2cf21 100644 --- a/crosvm_plugin/src/lib.rs +++ b/crosvm_plugin/src/lib.rs @@ -1049,7 +1049,7 @@ impl crosvm_vcpu { if *msr_count > msr_entries.len() { return Err(E2BIG); } - for (&msr_data, msr_entry) in get_msrs.get_entry_data().iter().zip(msr_entries.iter_mut()) { + for (&msr_data, msr_entry) in get_msrs.get_entry_data().iter().zip(msr_entries) { msr_entry.data = msr_data; } Ok(()) @@ -1059,7 +1059,7 @@ impl crosvm_vcpu { let mut r = VcpuRequest::new(); let set_msrs_entries: &mut RepeatedField<VcpuRequest_MsrEntry> = r.mut_set_msrs().mut_entries(); - for msr_entry in msr_entries.iter() { + for msr_entry in msr_entries { let mut entry = VcpuRequest_MsrEntry::new(); entry.index = msr_entry.index; entry.data = msr_entry.data; @@ -1073,7 +1073,7 @@ impl crosvm_vcpu { fn set_cpuid(&mut self, cpuid_entries: &[kvm_cpuid_entry2]) -> result::Result<(), c_int> { let mut r = VcpuRequest::new(); let set_cpuid_entries: &mut RepeatedField<CpuidEntry> = r.mut_set_cpuid().mut_entries(); - for cpuid_entry in cpuid_entries.iter() { + for cpuid_entry in cpuid_entries { set_cpuid_entries.push(cpuid_kvm_to_proto(cpuid_entry)); } diff --git a/devices/src/utils/event_loop.rs b/devices/src/utils/event_loop.rs index 2abcfda..b420dcf 100644 --- a/devices/src/utils/event_loop.rs +++ b/devices/src/utils/event_loop.rs @@ -106,7 +106,7 @@ impl EventLoop { return; } }; - for event in events.iter() { + for event in &events { if event.token().as_raw_fd() == stop_evt.as_raw_fd() { return; } else { diff --git a/devices/src/virtio/virtio_pci_device.rs b/devices/src/virtio/virtio_pci_device.rs index 337b7bb..5b54de5 100644 --- a/devices/src/virtio/virtio_pci_device.rs +++ b/devices/src/virtio/virtio_pci_device.rs @@ -167,7 +167,7 @@ impl VirtioPciDevice { /// Constructs a new PCI transport for the given virtio device. pub fn new(mem: GuestMemory, device: Box<dyn VirtioDevice>) -> Result<Self> { let mut queue_evts = Vec::new(); - for _ in device.queue_max_sizes().iter() { + for _ in device.queue_max_sizes() { queue_evts.push(EventFd::new()?) } let queues = device diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs index 3bc9c07..77ee136 100644 --- a/devices/src/virtio/wl.rs +++ b/devices/src/virtio/wl.rs @@ -1187,7 +1187,7 @@ impl WlState { fn close(&mut self, vfd_id: u32) -> WlResult<WlResp> { let mut to_delete = Set::new(); - for (dest_vfd_id, q) in self.in_queue.iter() { + for (dest_vfd_id, q) in &self.in_queue { if *dest_vfd_id == vfd_id { if let WlRecv::Vfd { id } = q { to_delete.insert(*id); @@ -1226,7 +1226,7 @@ impl WlState { vfds.copy_to(&mut vfd_ids[..]); send_vfd_ids[..vfd_count] .iter_mut() - .zip(vfd_ids[..vfd_count].iter()) + .zip(&vfd_ids[..vfd_count]) .for_each(|(send_vfd_id, &vfd_id)| { *send_vfd_id = CtrlVfdSendVfd { kind: Le32::from(VIRTIO_WL_CTRL_VFD_SEND_KIND_LOCAL), @@ -1551,7 +1551,7 @@ impl Worker { } }; - for event in events.iter() { + for event in &events { match event.token() { Token::InQueue => { let _ = in_queue_evt.read(); diff --git a/gpu_renderer/src/command_buffer.rs b/gpu_renderer/src/command_buffer.rs index 1f5b98a..b6c7005 100644 --- a/gpu_renderer/src/command_buffer.rs +++ b/gpu_renderer/src/command_buffer.rs @@ -89,7 +89,7 @@ impl CommandBufferBuilder { pub fn e_clear(&mut self, buffers: u32, color: [f32; 4], depth: f64, stencil: u32) { self.push_cmd(VIRGL_CCMD_CLEAR, 0, VIRGL_OBJ_CLEAR_SIZE); self.push(buffers); - for &c in color.iter() { + for c in &color { self.push(c.to_bits()) } self.push_qw(depth.to_bits()); diff --git a/gpu_renderer/src/lib.rs b/gpu_renderer/src/lib.rs index caa9f8e..8d03673 100644 --- a/gpu_renderer/src/lib.rs +++ b/gpu_renderer/src/lib.rs @@ -792,7 +792,7 @@ impl Resource { } self.detach_backing(); self.backing_mem = Some(mem.clone()); - for &(addr, len) in iovecs.iter() { + for &(addr, len) in iovecs { // Unwrap will not panic because we already checked the slices. let slice = mem.get_slice(addr.offset(), len as u64).unwrap(); self.backing_iovecs.push(VirglVec { diff --git a/qcow/src/qcow.rs b/qcow/src/qcow.rs index 9b301a5..d7759eb 100644 --- a/qcow/src/qcow.rs +++ b/qcow/src/qcow.rs @@ -682,7 +682,7 @@ impl QcowFile { let refcount_table_entries = div_round_up_u64(refblock_clusters, pointers_per_cluster); let mut ref_table = vec![0; refcount_table_entries as usize]; let mut first_free_cluster: u64 = 0; - for refblock_addr in ref_table.iter_mut() { + for refblock_addr in &mut ref_table { while refcounts[first_free_cluster as usize] != 0 { first_free_cluster += 1; if first_free_cluster >= refcounts.len() as u64 { @@ -1335,7 +1335,7 @@ impl Read for QcowFile { .read_exact(&mut buf[nread..(nread + count)])?; } else { // Previously unwritten region, return zeros - for b in (&mut buf[nread..(nread + count)]).iter_mut() { + for b in &mut buf[nread..(nread + count)] { *b = 0; } } @@ -2161,7 +2161,7 @@ mod tests { }, ]; - for xfer in xfers.iter() { + for xfer in &xfers { q.seek(SeekFrom::Start(xfer.addr)).expect("Failed to seek."); if xfer.write { q.write(&b).expect("Failed to write."); diff --git a/qcow/src/qcow_raw_file.rs b/qcow/src/qcow_raw_file.rs index 162e6fe..456b986 100644 --- a/qcow/src/qcow_raw_file.rs +++ b/qcow/src/qcow_raw_file.rs @@ -42,7 +42,7 @@ impl QcowRawFile { self.file.seek(SeekFrom::Start(offset))?; self.file.read_u64_into::<BigEndian>(&mut table)?; if let Some(m) = mask { - for ptr in table.iter_mut() { + for ptr in &mut table { *ptr &= m; } } diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index beedea4..d0809c6 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -501,7 +501,7 @@ pub fn run_config(cfg: Config) -> Result<()> { // Mount minimal set of devices (full, zero, urandom, etc). We can not use // jail.mount_dev() here because crosvm may not be running with CAP_SYS_ADMIN. let device_names = ["full", "null", "urandom", "zero"]; - for name in device_names.iter() { + for name in &device_names { let device = Path::new("/dev").join(&name); jail.mount_bind(&device, &device, true) .map_err(Error::MountDev)?; diff --git a/src/plugin/process.rs b/src/plugin/process.rs index 1c77dee..3e9655c 100644 --- a/src/plugin/process.rs +++ b/src/plugin/process.rs @@ -257,7 +257,7 @@ impl Process { self.kill_evt.write(1)?; // By shutting down our half of the VCPU sockets, any blocked calls in the VCPU threads will // unblock, allowing them to exit cleanly. - for sock in self.vcpu_sockets.iter() { + for sock in &self.vcpu_sockets { sock.0.shutdown(Shutdown::Both)?; } Ok(()) @@ -377,7 +377,7 @@ impl Process { irq_routing: &MainRequest_SetIrqRouting, ) -> SysResult<()> { let mut routes = Vec::with_capacity(irq_routing.routes.len()); - for route in irq_routing.routes.iter() { + for route in &irq_routing.routes { routes.push(IrqRoute { gsi: route.irq_id, source: if route.has_irqchip() { @@ -404,10 +404,8 @@ impl Process { } fn handle_pause_vcpus(&self, vcpu_handles: &[JoinHandle<()>], cpu_mask: u64, user_data: u64) { - for (cpu_id, (handle, per_cpu_state)) in vcpu_handles - .iter() - .zip(self.per_vcpu_states.iter()) - .enumerate() + for (cpu_id, (handle, per_cpu_state)) in + vcpu_handles.iter().zip(&self.per_vcpu_states).enumerate() { if cpu_mask & (1 << cpu_id) != 0 { per_cpu_state.lock().request_pause(user_data); diff --git a/src/plugin/vcpu.rs b/src/plugin/vcpu.rs index 1b65d43..eb7128c 100644 --- a/src/plugin/vcpu.rs +++ b/src/plugin/vcpu.rs @@ -467,7 +467,7 @@ impl PluginVcpu { // valid. let kvm_msr_entries: &mut [kvm_msr_entry] = kvm_msrs.entries.as_mut_slice(request_entries.len()); - for (msr_entry, entry) in kvm_msr_entries.iter_mut().zip(request_entries.iter()) { + for (msr_entry, entry) in kvm_msr_entries.iter_mut().zip(request_entries) { msr_entry.index = entry.index; msr_entry.data = entry.data; } diff --git a/sys_util/src/affinity.rs b/sys_util/src/affinity.rs index d166562..d91d3da 100644 --- a/sys_util/src/affinity.rs +++ b/sys_util/src/affinity.rs @@ -21,7 +21,7 @@ impl FromIterator<usize> for CpuSet { let mut cpuset: cpu_set_t = unsafe { mem::zeroed() }; // Safe because we pass a valid cpuset pointer. unsafe { CPU_ZERO(&mut cpuset) }; - for cpu in cpus.into_iter() { + for cpu in cpus { // Safe because we pass a valid cpuset pointer and cpu index. unsafe { CPU_SET(cpu, &mut cpuset) }; } diff --git a/sys_util/src/guest_memory.rs b/sys_util/src/guest_memory.rs index 25b4d4b..aad5b37 100644 --- a/sys_util/src/guest_memory.rs +++ b/sys_util/src/guest_memory.rs @@ -105,7 +105,7 @@ impl GuestMemory { fn create_memfd(ranges: &[(GuestAddress, u64)]) -> Result<SharedMemory> { let mut aligned_size = 0; let pg_size = pagesize(); - for range in ranges.iter() { + for range in ranges { if range.1 % pg_size as u64 != 0 { return Err(Error::MemoryNotAligned); } @@ -154,7 +154,7 @@ impl GuestMemory { let mut regions = Vec::<MemoryRegion>::new(); let mut offset = 0; - for range in ranges.iter() { + for range in ranges { if let Some(last) = regions.last() { if last .guest_base diff --git a/sys_util/src/net.rs b/sys_util/src/net.rs index 36b696e..0afb692 100644 --- a/sys_util/src/net.rs +++ b/sys_util/src/net.rs @@ -53,7 +53,7 @@ fn sockaddr_un<P: AsRef<Path>>(path: P) -> io::Result<(libc::sockaddr_un, libc:: }; // Copy data from `path` to `addr.sun_path` - for (dst, src) in addr.sun_path.iter_mut().zip(bytes.iter()) { + for (dst, src) in addr.sun_path.iter_mut().zip(bytes) { *dst = *src as libc::c_char; } diff --git a/sys_util/src/poll.rs b/sys_util/src/poll.rs index 2f15198..0da0831 100644 --- a/sys_util/src/poll.rs +++ b/sys_util/src/poll.rs @@ -211,6 +211,15 @@ impl<'a, T: PollToken> PollEvents<'a, T> { } } +impl<'a, T: PollToken> IntoIterator for &'a PollEvents<'_, T> { + type Item = PollEvent<'a, T>; + type IntoIter = PollEventIter<'a, slice::Iter<'a, epoll_event>, T>; + + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + /// A deep copy of the event records from `PollEvents`. pub struct PollEventsOwned<T> { count: usize, diff --git a/sys_util/src/write_zeroes.rs b/sys_util/src/write_zeroes.rs index 8c7f775..51f0dbe 100644 --- a/sys_util/src/write_zeroes.rs +++ b/sys_util/src/write_zeroes.rs @@ -86,15 +86,15 @@ mod tests { f.seek(SeekFrom::Start(0)).unwrap(); f.read(&mut readback).unwrap(); // Bytes before the write should still be 0 - for read in readback[0..1234].iter() { + for read in &readback[0..1234] { assert_eq!(*read, 0); } // Bytes that were just written should be 0x55 - for read in readback[1234..(1234 + 5678)].iter() { + for read in &readback[1234..(1234 + 5678)] { assert_eq!(*read, 0x55); } // Bytes after the written area should still be 0 - for read in readback[(1234 + 5678)..].iter() { + for read in &readback[(1234 + 5678)..] { assert_eq!(*read, 0); } @@ -108,23 +108,23 @@ mod tests { f.seek(SeekFrom::Start(0)).unwrap(); f.read(&mut readback).unwrap(); // Bytes before the write should still be 0 - for read in readback[0..1234].iter() { + for read in &readback[0..1234] { assert_eq!(*read, 0); } // Original data should still exist before the write_zeroes region - for read in readback[1234..2345].iter() { + for read in &readback[1234..2345] { assert_eq!(*read, 0x55); } // The write_zeroes region should now be zero - for read in readback[2345..(2345 + 4321)].iter() { + for read in &readback[2345..(2345 + 4321)] { assert_eq!(*read, 0); } // Original data should still exist after the write_zeroes region - for read in readback[(2345 + 4321)..(1234 + 5678)].iter() { + for read in &readback[(2345 + 4321)..(1234 + 5678)] { assert_eq!(*read, 0x55); } // The rest of the file should still be 0 - for read in readback[(1234 + 5678)..].iter() { + for read in &readback[(1234 + 5678)..] { assert_eq!(*read, 0); } } @@ -158,11 +158,11 @@ mod tests { f.seek(SeekFrom::Start(0)).unwrap(); f.read(&mut readback).unwrap(); // The write_zeroes region should now be zero - for read in readback[0..0x10001].iter() { + for read in &readback[0..0x10001] { assert_eq!(*read, 0); } // Original data should still exist after the write_zeroes region - for read in readback[0x10001..0x20000].iter() { + for read in &readback[0x10001..0x20000] { assert_eq!(*read, 0x55); } } diff --git a/x86_64/src/cpuid.rs b/x86_64/src/cpuid.rs index 0a70a21..9f76550 100644 --- a/x86_64/src/cpuid.rs +++ b/x86_64/src/cpuid.rs @@ -53,7 +53,7 @@ const EDX_HTT_SHIFT: u32 = 28; // Hyper Threading Enabled. fn filter_cpuid(cpu_id: u64, cpu_count: u64, kvm_cpuid: &mut kvm::CpuId) -> Result<()> { let entries = kvm_cpuid.mut_entries_slice(); - for entry in entries.iter_mut() { + for entry in entries { match entry.function { 1 => { // X86 hypervisor feature diff --git a/x86_64/src/mptable.rs b/x86_64/src/mptable.rs index 9277840..c2def2f 100644 --- a/x86_64/src/mptable.rs +++ b/x86_64/src/mptable.rs @@ -89,7 +89,7 @@ fn compute_checksum<T: Copy>(v: &T) -> u8 { // Safe because we are only reading the bytes within the size of the `T` reference `v`. let v_slice = unsafe { slice::from_raw_parts(v as *const T as *const u8, mem::size_of::<T>()) }; let mut checksum: u8 = 0; - for i in v_slice.iter() { + for i in v_slice { checksum = checksum.wrapping_add(*i); } checksum |