apply is_multiple_of lint

This commit is contained in:
auronandace
2026-02-21 08:39:26 +00:00
parent 02a68d3c87
commit df469ddcb3
10 changed files with 27 additions and 30 deletions
+4 -4
View File
@@ -590,10 +590,10 @@ pub fn mremap(
flags: usize,
token: &mut CleanLockToken,
) -> Result<usize> {
if old_address % PAGE_SIZE != 0
|| old_size % PAGE_SIZE != 0
|| new_address % PAGE_SIZE != 0
|| new_size % PAGE_SIZE != 0
if !old_address.is_multiple_of(PAGE_SIZE)
|| !old_size.is_multiple_of(PAGE_SIZE)
|| !new_address.is_multiple_of(PAGE_SIZE)
|| !new_size.is_multiple_of(PAGE_SIZE)
{
return Err(Error::new(EINVAL));
}
+3 -3
View File
@@ -102,7 +102,7 @@ pub fn futex(
let (fetched, expected) = if op == FUTEX_WAIT {
// Must be aligned, otherwise it could cross a page boundary and mess up the
// (simpler) validation we did in the first place.
if addr % 4 != 0 {
if !addr.is_multiple_of(4) {
return Err(Error::new(EINVAL));
}
@@ -123,7 +123,7 @@ pub fn futex(
use core::sync::atomic::AtomicU64;
// op == FUTEX_WAIT64
if addr % 8 != 0 {
if !addr.is_multiple_of(8) {
return Err(Error::new(EINVAL));
}
(
@@ -157,7 +157,7 @@ pub fn futex(
futexes
.entry(target_physaddr)
.or_insert_with(|| Vec::new())
.or_insert_with(Vec::new)
.push(FutexEntry {
target_virtaddr,
context_lock: context_lock.clone(),
+1 -1
View File
@@ -80,7 +80,7 @@ pub fn mprotect(address: usize, size: usize, flags: MapFlags) -> Result<()> {
const KERNEL_METADATA_BASE: usize = crate::USER_END_OFFSET - syscall::KERNEL_METADATA_SIZE;
const KERNEL_METADATA_PAGE_COUNT: usize = syscall::KERNEL_METADATA_SIZE / PAGE_SIZE + {
if syscall::KERNEL_METADATA_SIZE % PAGE_SIZE == 0 {
if syscall::KERNEL_METADATA_SIZE.is_multiple_of(PAGE_SIZE) {
0
} else {
1
+1 -1
View File
@@ -228,7 +228,7 @@ fn is_kernel_mem(slice: &[u8]) -> bool {
/// - the region is empty (EINVAL), or
/// - any byte in the region exceeds USER_END_OFFSET (EFAULT).
pub fn validate_region(address: usize, size: usize) -> Result<PageSpan> {
if address % PAGE_SIZE != 0 || size % PAGE_SIZE != 0 || size == 0 {
if !address.is_multiple_of(PAGE_SIZE) || !size.is_multiple_of(PAGE_SIZE) || size == 0 {
return Err(Error::new(EINVAL));
}
if address.saturating_add(size) > crate::USER_END_OFFSET {