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:
Songqian Li 2025-08-06 16:41:29 +08:00 committed by Bo Chen
parent 394fd230b0
commit cd2c43b489
13 changed files with 24 additions and 27 deletions

View file

@ -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,
// - If failed, print it as u32 array.
let value_result = match CStr::from_bytes_with_nul(value) {
Ok(value_cstr) => match value_cstr.to_str() {
Ok(value_str) => Some(value_str),
Err(_e) => None,
},
Ok(value_cstr) => value_cstr.to_str().ok(),
Err(_e) => None,
};

View file

@ -431,7 +431,7 @@ impl Request {
// In case it's not properly aligned, an intermediate buffer is
// created with the correct alignment, and a copy from/to the
// 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();
// SAFETY: layout has non-zero size
let aligned_ptr = unsafe { alloc_zeroed(layout) };

View file

@ -1705,12 +1705,12 @@ fn offset_is_cluster_boundary(offset: u64, cluster_bits: u32) -> Result<()> {
// Ceiling of the division of `dividend`/`divisor`.
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`.
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<()>

View file

@ -89,9 +89,9 @@ impl RawFile {
let align64: u64 = self.alignment.try_into().unwrap();
(self.position % align64 == 0)
&& ((buf.as_ptr() as usize) % self.alignment == 0)
&& (buf.len() % self.alignment == 0)
self.position.is_multiple_of(align64)
&& (buf.as_ptr() as usize).is_multiple_of(self.alignment)
&& buf.len().is_multiple_of(self.alignment)
}
pub fn set_len(&self, size: u64) -> std::io::Result<()> {

View file

@ -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
// a register relates to multiple interrupts.
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;
}
}

View file

@ -265,7 +265,7 @@ impl BalloonEpollHandler {
error!("The head contains the request type is not right");
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());
return Err(Error::InvalidRequest);
}

View file

@ -193,35 +193,35 @@ unsafe impl ByteValued for VirtioMemConfig {}
impl VirtioMemConfig {
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!(
"addr 0x{:x} is not aligned on block_size 0x{:x}",
self.addr,
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!(
"region_size 0x{:x} is not aligned on block_size 0x{:x}",
self.region_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!(
"usable_region_size 0x{:x} is not aligned on block_size 0x{:x}",
self.usable_region_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!(
"plugged_size 0x{:x} is not aligned on block_size 0x{:x}",
self.plugged_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!(
"requested_size 0x{:x} is not aligned on block_size 0x{:x}",
self.requested_size,
@ -244,7 +244,7 @@ impl VirtioMemConfig {
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!(
"new size 0x{:x} is not aligned on block_size 0x{:x}",
size,
@ -267,7 +267,7 @@ impl VirtioMemConfig {
// Start address must be aligned on block_size, the size must be
// greater than 0, and all blocks covered by the request must be
// in the usable region.
if addr % self.block_size != 0
if !addr.is_multiple_of(self.block_size)
|| size == 0
|| (addr < self.addr || addr + size > self.addr + self.usable_region_size)
{

View file

@ -706,7 +706,7 @@ impl VirtioDevice for Net {
let num_queues = queues.len();
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 (_, mut ctrl_queue, ctrl_queue_evt) = queues.remove(ctrl_queue_index);

View file

@ -298,7 +298,7 @@ impl VirtioDevice for Net {
let num_queues = queues.len();
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 (_, mut ctrl_queue, ctrl_queue_evt) = queues.remove(ctrl_queue_index);

View file

@ -68,7 +68,7 @@ impl AddressAllocator {
}
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)
} else {
0

View file

@ -264,7 +264,7 @@ impl MemoryRangeTable {
}
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();
data.resize_with(

View file

@ -66,8 +66,8 @@ enum ParameterAreaState {
#[cfg(feature = "sev_snp")]
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.1 - ram_range.0) % HV_PAGE_SIZE == 0);
assert!(ram_range.0.is_multiple_of(HV_PAGE_SIZE));
assert!((ram_range.1 - ram_range.0).is_multiple_of(HV_PAGE_SIZE));
IGVM_VHS_MEMORY_MAP_ENTRY {
starting_gpa_page_number: ram_range.0 / HV_PAGE_SIZE,
@ -179,7 +179,7 @@ pub fn load_igvm(
data_type,
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
assert!(data.len() as u64 == HV_PAGE_SIZE || data.is_empty());

View file

@ -1700,7 +1700,7 @@ impl MemoryManager {
}
// "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);
}