mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Fix beta clippy errors
Fix clippy error: "error: manual implementation of `.is_multiple_of() `" from rustc 1.90.0-beta.1 (788da80fc 2025-08-04). Signed-off-by: Songqian Li <sionli@tencent.com>
This commit is contained in:
@@ -448,10 +448,7 @@ fn print_node(node: fdt_parser::node::FdtNode<'_, '_>, n_spaces: usize) {
|
|||||||
// - At first, try to convert it to CStr and print,
|
// - At first, try to convert it to CStr and print,
|
||||||
// - If failed, print it as u32 array.
|
// - If failed, print it as u32 array.
|
||||||
let value_result = match CStr::from_bytes_with_nul(value) {
|
let value_result = match CStr::from_bytes_with_nul(value) {
|
||||||
Ok(value_cstr) => match value_cstr.to_str() {
|
Ok(value_cstr) => value_cstr.to_str().ok(),
|
||||||
Ok(value_str) => Some(value_str),
|
|
||||||
Err(_e) => None,
|
|
||||||
},
|
|
||||||
Err(_e) => None,
|
Err(_e) => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -431,7 +431,7 @@ impl Request {
|
|||||||
// In case it's not properly aligned, an intermediate buffer is
|
// In case it's not properly aligned, an intermediate buffer is
|
||||||
// created with the correct alignment, and a copy from/to the
|
// created with the correct alignment, and a copy from/to the
|
||||||
// origin buffer is performed, depending on the type of operation.
|
// origin buffer is performed, depending on the type of operation.
|
||||||
let iov_base = if (origin_ptr.as_ptr() as u64) % SECTOR_SIZE != 0 {
|
let iov_base = if !(origin_ptr.as_ptr() as u64).is_multiple_of(SECTOR_SIZE) {
|
||||||
let layout = Layout::from_size_align(data_len, SECTOR_SIZE as usize).unwrap();
|
let layout = Layout::from_size_align(data_len, SECTOR_SIZE as usize).unwrap();
|
||||||
// SAFETY: layout has non-zero size
|
// SAFETY: layout has non-zero size
|
||||||
let aligned_ptr = unsafe { alloc_zeroed(layout) };
|
let aligned_ptr = unsafe { alloc_zeroed(layout) };
|
||||||
|
|||||||
@@ -1705,12 +1705,12 @@ fn offset_is_cluster_boundary(offset: u64, cluster_bits: u32) -> Result<()> {
|
|||||||
|
|
||||||
// Ceiling of the division of `dividend`/`divisor`.
|
// Ceiling of the division of `dividend`/`divisor`.
|
||||||
fn div_round_up_u64(dividend: u64, divisor: u64) -> u64 {
|
fn div_round_up_u64(dividend: u64, divisor: u64) -> u64 {
|
||||||
dividend / divisor + u64::from(dividend % divisor != 0)
|
dividend / divisor + u64::from(!dividend.is_multiple_of(divisor))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ceiling of the division of `dividend`/`divisor`.
|
// Ceiling of the division of `dividend`/`divisor`.
|
||||||
fn div_round_up_u32(dividend: u32, divisor: u32) -> u32 {
|
fn div_round_up_u32(dividend: u32, divisor: u32) -> u32 {
|
||||||
dividend / divisor + u32::from(dividend % divisor != 0)
|
dividend / divisor + u32::from(!dividend.is_multiple_of(divisor))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_copy<R, W>(reader: &mut R, writer: &mut W, offset: u64, size: u64) -> Result<()>
|
fn convert_copy<R, W>(reader: &mut R, writer: &mut W, offset: u64, size: u64) -> Result<()>
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ impl RawFile {
|
|||||||
|
|
||||||
let align64: u64 = self.alignment.try_into().unwrap();
|
let align64: u64 = self.alignment.try_into().unwrap();
|
||||||
|
|
||||||
(self.position % align64 == 0)
|
self.position.is_multiple_of(align64)
|
||||||
&& ((buf.as_ptr() as usize) % self.alignment == 0)
|
&& (buf.as_ptr() as usize).is_multiple_of(self.alignment)
|
||||||
&& (buf.len() % self.alignment == 0)
|
&& buf.len().is_multiple_of(self.alignment)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_len(&self, size: u64) -> std::io::Result<()> {
|
pub fn set_len(&self, size: u64) -> std::io::Result<()> {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ fn compute_reg_len(gic: &DeviceFd, reg: &DistReg, base: u32) -> Result<u32> {
|
|||||||
// that the model has. It is also the type of register where
|
// that the model has. It is also the type of register where
|
||||||
// a register relates to multiple interrupts.
|
// a register relates to multiple interrupts.
|
||||||
end = base + (reg.bpi as u32 * (num_irq - LAYOUT_IRQ_BASE) / 8);
|
end = base + (reg.bpi as u32 * (num_irq - LAYOUT_IRQ_BASE) / 8);
|
||||||
if reg.bpi as u32 * (num_irq - LAYOUT_IRQ_BASE) % 8 > 0 {
|
if !(reg.bpi as u32 * (num_irq - LAYOUT_IRQ_BASE)).is_multiple_of(8) {
|
||||||
end += REG_SIZE as u32;
|
end += REG_SIZE as u32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ impl BalloonEpollHandler {
|
|||||||
error!("The head contains the request type is not right");
|
error!("The head contains the request type is not right");
|
||||||
return Err(Error::UnexpectedWriteOnlyDescriptor);
|
return Err(Error::UnexpectedWriteOnlyDescriptor);
|
||||||
}
|
}
|
||||||
if desc.len() as usize % data_chunk_size != 0 {
|
if !(desc.len() as usize).is_multiple_of(data_chunk_size) {
|
||||||
error!("the request size {} is not right", desc.len());
|
error!("the request size {} is not right", desc.len());
|
||||||
return Err(Error::InvalidRequest);
|
return Err(Error::InvalidRequest);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,35 +193,35 @@ unsafe impl ByteValued for VirtioMemConfig {}
|
|||||||
|
|
||||||
impl VirtioMemConfig {
|
impl VirtioMemConfig {
|
||||||
fn validate(&self) -> result::Result<(), Error> {
|
fn validate(&self) -> result::Result<(), Error> {
|
||||||
if self.addr % self.block_size != 0 {
|
if !self.addr.is_multiple_of(self.block_size) {
|
||||||
return Err(Error::ValidateError(anyhow!(
|
return Err(Error::ValidateError(anyhow!(
|
||||||
"addr 0x{:x} is not aligned on block_size 0x{:x}",
|
"addr 0x{:x} is not aligned on block_size 0x{:x}",
|
||||||
self.addr,
|
self.addr,
|
||||||
self.block_size
|
self.block_size
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if self.region_size % self.block_size != 0 {
|
if !self.region_size.is_multiple_of(self.block_size) {
|
||||||
return Err(Error::ValidateError(anyhow!(
|
return Err(Error::ValidateError(anyhow!(
|
||||||
"region_size 0x{:x} is not aligned on block_size 0x{:x}",
|
"region_size 0x{:x} is not aligned on block_size 0x{:x}",
|
||||||
self.region_size,
|
self.region_size,
|
||||||
self.block_size
|
self.block_size
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if self.usable_region_size % self.block_size != 0 {
|
if !self.usable_region_size.is_multiple_of(self.block_size) {
|
||||||
return Err(Error::ValidateError(anyhow!(
|
return Err(Error::ValidateError(anyhow!(
|
||||||
"usable_region_size 0x{:x} is not aligned on block_size 0x{:x}",
|
"usable_region_size 0x{:x} is not aligned on block_size 0x{:x}",
|
||||||
self.usable_region_size,
|
self.usable_region_size,
|
||||||
self.block_size
|
self.block_size
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if self.plugged_size % self.block_size != 0 {
|
if !self.plugged_size.is_multiple_of(self.block_size) {
|
||||||
return Err(Error::ValidateError(anyhow!(
|
return Err(Error::ValidateError(anyhow!(
|
||||||
"plugged_size 0x{:x} is not aligned on block_size 0x{:x}",
|
"plugged_size 0x{:x} is not aligned on block_size 0x{:x}",
|
||||||
self.plugged_size,
|
self.plugged_size,
|
||||||
self.block_size
|
self.block_size
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if self.requested_size % self.block_size != 0 {
|
if !self.requested_size.is_multiple_of(self.block_size) {
|
||||||
return Err(Error::ValidateError(anyhow!(
|
return Err(Error::ValidateError(anyhow!(
|
||||||
"requested_size 0x{:x} is not aligned on block_size 0x{:x}",
|
"requested_size 0x{:x} is not aligned on block_size 0x{:x}",
|
||||||
self.requested_size,
|
self.requested_size,
|
||||||
@@ -244,7 +244,7 @@ impl VirtioMemConfig {
|
|||||||
size,
|
size,
|
||||||
self.region_size
|
self.region_size
|
||||||
)));
|
)));
|
||||||
} else if size % self.block_size != 0 {
|
} else if !size.is_multiple_of(self.block_size) {
|
||||||
return Err(Error::ResizeError(anyhow!(
|
return Err(Error::ResizeError(anyhow!(
|
||||||
"new size 0x{:x} is not aligned on block_size 0x{:x}",
|
"new size 0x{:x} is not aligned on block_size 0x{:x}",
|
||||||
size,
|
size,
|
||||||
@@ -267,7 +267,7 @@ impl VirtioMemConfig {
|
|||||||
// Start address must be aligned on block_size, the size must be
|
// Start address must be aligned on block_size, the size must be
|
||||||
// greater than 0, and all blocks covered by the request must be
|
// greater than 0, and all blocks covered by the request must be
|
||||||
// in the usable region.
|
// in the usable region.
|
||||||
if addr % self.block_size != 0
|
if !addr.is_multiple_of(self.block_size)
|
||||||
|| size == 0
|
|| size == 0
|
||||||
|| (addr < self.addr || addr + size > self.addr + self.usable_region_size)
|
|| (addr < self.addr || addr + size > self.addr + self.usable_region_size)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -706,7 +706,7 @@ impl VirtioDevice for Net {
|
|||||||
|
|
||||||
let num_queues = queues.len();
|
let num_queues = queues.len();
|
||||||
let event_idx = self.common.feature_acked(VIRTIO_RING_F_EVENT_IDX.into());
|
let event_idx = self.common.feature_acked(VIRTIO_RING_F_EVENT_IDX.into());
|
||||||
if self.common.feature_acked(VIRTIO_NET_F_CTRL_VQ.into()) && num_queues % 2 != 0 {
|
if self.common.feature_acked(VIRTIO_NET_F_CTRL_VQ.into()) && !num_queues.is_multiple_of(2) {
|
||||||
let ctrl_queue_index = num_queues - 1;
|
let ctrl_queue_index = num_queues - 1;
|
||||||
let (_, mut ctrl_queue, ctrl_queue_evt) = queues.remove(ctrl_queue_index);
|
let (_, mut ctrl_queue, ctrl_queue_evt) = queues.remove(ctrl_queue_index);
|
||||||
|
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ impl VirtioDevice for Net {
|
|||||||
|
|
||||||
let num_queues = queues.len();
|
let num_queues = queues.len();
|
||||||
let event_idx = self.common.feature_acked(VIRTIO_RING_F_EVENT_IDX.into());
|
let event_idx = self.common.feature_acked(VIRTIO_RING_F_EVENT_IDX.into());
|
||||||
if self.common.feature_acked(VIRTIO_NET_F_CTRL_VQ.into()) && num_queues % 2 != 0 {
|
if self.common.feature_acked(VIRTIO_NET_F_CTRL_VQ.into()) && !num_queues.is_multiple_of(2) {
|
||||||
let ctrl_queue_index = num_queues - 1;
|
let ctrl_queue_index = num_queues - 1;
|
||||||
let (_, mut ctrl_queue, ctrl_queue_evt) = queues.remove(ctrl_queue_index);
|
let (_, mut ctrl_queue, ctrl_queue_evt) = queues.remove(ctrl_queue_index);
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ impl AddressAllocator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn align_address(&self, address: GuestAddress, alignment: GuestUsize) -> GuestAddress {
|
fn align_address(&self, address: GuestAddress, alignment: GuestUsize) -> GuestAddress {
|
||||||
let align_adjust = if address.raw_value() % alignment != 0 {
|
let align_adjust = if !address.raw_value().is_multiple_of(alignment) {
|
||||||
alignment - (address.raw_value() % alignment)
|
alignment - (address.raw_value() % alignment)
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ impl MemoryRangeTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_from(fd: &mut dyn Read, length: u64) -> Result<MemoryRangeTable, MigratableError> {
|
pub fn read_from(fd: &mut dyn Read, length: u64) -> Result<MemoryRangeTable, MigratableError> {
|
||||||
assert!(length as usize % std::mem::size_of::<MemoryRange>() == 0);
|
assert!((length as usize).is_multiple_of(size_of::<MemoryRange>()));
|
||||||
|
|
||||||
let mut data: Vec<MemoryRange> = Vec::new();
|
let mut data: Vec<MemoryRange> = Vec::new();
|
||||||
data.resize_with(
|
data.resize_with(
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ enum ParameterAreaState {
|
|||||||
|
|
||||||
#[cfg(feature = "sev_snp")]
|
#[cfg(feature = "sev_snp")]
|
||||||
fn igvm_memmap_from_ram_range(ram_range: (u64, u64)) -> IGVM_VHS_MEMORY_MAP_ENTRY {
|
fn igvm_memmap_from_ram_range(ram_range: (u64, u64)) -> IGVM_VHS_MEMORY_MAP_ENTRY {
|
||||||
assert!(ram_range.0 % HV_PAGE_SIZE == 0);
|
assert!(ram_range.0.is_multiple_of(HV_PAGE_SIZE));
|
||||||
assert!((ram_range.1 - ram_range.0) % HV_PAGE_SIZE == 0);
|
assert!((ram_range.1 - ram_range.0).is_multiple_of(HV_PAGE_SIZE));
|
||||||
|
|
||||||
IGVM_VHS_MEMORY_MAP_ENTRY {
|
IGVM_VHS_MEMORY_MAP_ENTRY {
|
||||||
starting_gpa_page_number: ram_range.0 / HV_PAGE_SIZE,
|
starting_gpa_page_number: ram_range.0 / HV_PAGE_SIZE,
|
||||||
@@ -179,7 +179,7 @@ pub fn load_igvm(
|
|||||||
data_type,
|
data_type,
|
||||||
data,
|
data,
|
||||||
} => {
|
} => {
|
||||||
debug_assert!(data.len() as u64 % HV_PAGE_SIZE == 0);
|
debug_assert!((data.len() as u64).is_multiple_of(HV_PAGE_SIZE));
|
||||||
|
|
||||||
// TODO: only 4k or empty page data supported right now
|
// TODO: only 4k or empty page data supported right now
|
||||||
assert!(data.len() as u64 == HV_PAGE_SIZE || data.is_empty());
|
assert!(data.len() as u64 == HV_PAGE_SIZE || data.is_empty());
|
||||||
|
|||||||
@@ -1700,7 +1700,7 @@ impl MemoryManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// "Inserted" DIMM must have a size that is a multiple of 128MiB
|
// "Inserted" DIMM must have a size that is a multiple of 128MiB
|
||||||
if size % (128 << 20) != 0 {
|
if !size.is_multiple_of(128 << 20) {
|
||||||
return Err(Error::InvalidSize);
|
return Err(Error::InvalidSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user