mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: use prelude size_of
size_of is part of std::prelude as of Rust 1.80 (with size_of_val, align_of, align_of_val), and the workspace MSRV is 1.89, so qualifying it (mem::size_of, std::mem::size_of, core::mem::size_of) is unnecessary. Convert every qualified size_of call-site to the bare prelude form and drop the now-redundant `use std::mem::size_of;` imports, keeping `use std::mem;` where it still serves non-prelude items (transmute, swap, replace, take, zeroed, MaybeUninit, offset_of). size_of is the only one of the four currently used in the tree. Pure refactor, no behavioural change. Follow-up to the clippy::absolute_paths cleanup (#7670), as discussed in #8444. Signed-off-by: Henry Hrvoje Tonkovac <htonkovac@gmail.com> Assisted-by: Claude:Opus-4.8
This commit is contained in:
committed by
Bo Chen
parent
f56fa3a865
commit
f720e619c1
@@ -15,7 +15,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
use std::io::{self, Write};
|
||||
use std::mem::size_of;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, Barrier};
|
||||
|
||||
@@ -666,8 +666,7 @@ impl BlockEpollHandler {
|
||||
if let Some(cpuset) = cpuset.as_ref() {
|
||||
let cpuset: *const libc::cpu_set_t = cpuset;
|
||||
// SAFETY: FFI call with correct arguments
|
||||
let ret =
|
||||
unsafe { libc::sched_setaffinity(0, mem::size_of::<libc::cpu_set_t>(), cpuset) };
|
||||
let ret = unsafe { libc::sched_setaffinity(0, size_of::<libc::cpu_set_t>(), cpuset) };
|
||||
|
||||
if ret != 0 {
|
||||
error!(
|
||||
@@ -1148,7 +1147,7 @@ impl VirtioDevice for Block {
|
||||
// The "writeback" field is the only mutable field
|
||||
let writeback_offset =
|
||||
(&raw const self.config.writeback as u64) - (&raw const self.config as u64);
|
||||
if offset != writeback_offset || data.len() != mem::size_of_val(&self.config.writeback) {
|
||||
if offset != writeback_offset || data.len() != size_of_val(&self.config.writeback) {
|
||||
error!(
|
||||
"Attempt to write to read-only field: offset {:x} length {}",
|
||||
offset,
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::mem::size_of;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Barrier, Mutex, RwLock};
|
||||
use std::{io, mem, result};
|
||||
use std::{io, result};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use event_monitor::event;
|
||||
@@ -1274,7 +1273,7 @@ impl VirtioDevice for Iommu {
|
||||
// The "bypass" field is the only mutable field
|
||||
let bypass_offset =
|
||||
(&raw const self.config.bypass as u64) - (&raw const self.config as u64);
|
||||
if offset != bypass_offset || data.len() != mem::size_of_val(&self.config.bypass) {
|
||||
if offset != bypass_offset || data.len() != size_of_val(&self.config.bypass) {
|
||||
error!(
|
||||
"Attempt to write to read-only field: offset {:x} length {}",
|
||||
offset,
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::mem::size_of;
|
||||
use std::os::unix::io::{AsRawFd, RawFd};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, Barrier, Mutex};
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||
|
||||
use std::fs::File;
|
||||
use std::mem::size_of;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, Barrier};
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
|
||||
//
|
||||
|
||||
use std::mem::size_of;
|
||||
use std::ops::Deref;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
@@ -8,11 +8,10 @@
|
||||
|
||||
use std::any::Any;
|
||||
use std::io::Write;
|
||||
use std::mem::size_of;
|
||||
use std::ops::Deref;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU16, AtomicUsize, Ordering};
|
||||
use std::sync::{Arc, Barrier, Mutex};
|
||||
use std::{cmp, io, mem, result};
|
||||
use std::{cmp, io, result};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use libc::EFD_NONBLOCK;
|
||||
@@ -91,7 +90,7 @@ const VIRTIO_PCI_CAP_LEN_OFFSET: u8 = 2;
|
||||
impl VirtioPciCap {
|
||||
pub fn new(cfg_type: PciCapabilityType, pci_bar: u8, offset: u32, length: u32) -> Self {
|
||||
VirtioPciCap {
|
||||
cap_len: (mem::size_of::<VirtioPciCap>() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET,
|
||||
cap_len: (size_of::<VirtioPciCap>() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET,
|
||||
cfg_type: cfg_type as u8,
|
||||
pci_bar,
|
||||
id: 0,
|
||||
@@ -131,7 +130,7 @@ impl VirtioPciNotifyCap {
|
||||
) -> Self {
|
||||
VirtioPciNotifyCap {
|
||||
cap: VirtioPciCap {
|
||||
cap_len: (mem::size_of::<VirtioPciNotifyCap>() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET,
|
||||
cap_len: (size_of::<VirtioPciNotifyCap>() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET,
|
||||
cfg_type: cfg_type as u8,
|
||||
pci_bar,
|
||||
id: 0,
|
||||
@@ -168,7 +167,7 @@ impl VirtioPciCap64 {
|
||||
pub fn new(cfg_type: PciCapabilityType, pci_bar: u8, id: u8, offset: u64, length: u64) -> Self {
|
||||
VirtioPciCap64 {
|
||||
cap: VirtioPciCap {
|
||||
cap_len: (mem::size_of::<VirtioPciCap64>() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET,
|
||||
cap_len: (size_of::<VirtioPciCap64>() as u8) + VIRTIO_PCI_CAP_LEN_OFFSET,
|
||||
cfg_type: cfg_type as u8,
|
||||
pci_bar,
|
||||
id,
|
||||
@@ -776,7 +775,7 @@ impl VirtioPciDevice {
|
||||
return;
|
||||
}
|
||||
|
||||
if offset < mem::size_of::<VirtioPciCap>() {
|
||||
if offset < size_of::<VirtioPciCap>() {
|
||||
if let Some(end) = offset.checked_add(data_len) {
|
||||
// This write can't fail, offset and end are checked against config_len.
|
||||
data.write_all(&cap_slice[offset..cmp::min(end, cap_len)])
|
||||
@@ -799,7 +798,7 @@ impl VirtioPciDevice {
|
||||
return None;
|
||||
}
|
||||
|
||||
if offset < mem::size_of::<VirtioPciCap>() {
|
||||
if offset < size_of::<VirtioPciCap>() {
|
||||
let (_, right) = cap_slice.split_at_mut(offset);
|
||||
right[..data_len].copy_from_slice(data);
|
||||
None
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{io, mem, result};
|
||||
use std::{io, result};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use event_monitor::event;
|
||||
@@ -253,7 +253,7 @@ impl Vdpa {
|
||||
.desc_table()
|
||||
.translate_gpa(
|
||||
self.common.access_platform().as_deref(),
|
||||
queue_size as usize * mem::size_of::<RawDescriptor>(),
|
||||
queue_size as usize * size_of::<RawDescriptor>(),
|
||||
)
|
||||
.map_err(Error::TranslateAddress)?,
|
||||
used_ring_addr: queue
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// Copyright 2019 Intel Corporation. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use std::result;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, Barrier, Mutex};
|
||||
use std::{mem, result};
|
||||
|
||||
use block::VirtioBlockConfig;
|
||||
use log::{error, info};
|
||||
@@ -138,7 +138,7 @@ impl Blk {
|
||||
return Err(Error::BadQueueNum);
|
||||
}
|
||||
|
||||
let config_len = mem::size_of::<VirtioBlockConfig>();
|
||||
let config_len = size_of::<VirtioBlockConfig>();
|
||||
let config_space: Vec<u8> = vec![0u8; config_len];
|
||||
let (_, config_space) = vu
|
||||
.socket_handle()
|
||||
@@ -237,7 +237,7 @@ impl VirtioDevice for Blk {
|
||||
// The "writeback" field is the only mutable field
|
||||
let writeback_offset =
|
||||
(&raw const self.config.writeback as u64) - (&raw const self.config as u64);
|
||||
if offset != writeback_offset || data.len() != mem::size_of_val(&self.config.writeback) {
|
||||
if offset != writeback_offset || data.len() != size_of_val(&self.config.writeback) {
|
||||
error!(
|
||||
"Attempt to write to read-only field: offset {:x} length {}",
|
||||
offset,
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::os::unix::net::{UnixListener, UnixStream};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{ffi, fs, io, mem, slice};
|
||||
use std::{ffi, fs, io, slice};
|
||||
|
||||
use log::{error, info};
|
||||
use vhost::vhost_kern::vhost_binding::VHOST_VRING_F_LOG;
|
||||
@@ -228,7 +228,7 @@ impl VhostUserHandle {
|
||||
desc_table_addr: get_host_address_range(
|
||||
mem,
|
||||
GuestAddress(queue.desc_table()),
|
||||
actual_size * mem::size_of::<RawDescriptor>(),
|
||||
actual_size * size_of::<RawDescriptor>(),
|
||||
)
|
||||
.ok_or(Error::DescriptorTableAddress)? as u64,
|
||||
// The used ring is {flags: u16; idx: u16; virtq_used_elem [{id: u16, len: u16}; actual_size]},
|
||||
|
||||
Reference in New Issue
Block a user