Skip to content

Commit f7862d0

Browse files
uefi: Use is_multiple_of
1 parent 13b80d0 commit f7862d0

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

uefi/src/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn alloc_pool_aligned(memory_type: MemoryType, size: usize, align: usize) -> *mu
8787
///
8888
/// [Rust type layout]: https://doc.rust-lang.org/reference/type-layout.html
8989
const fn layout_allows_page_alloc_shortcut(layout: &Layout) -> bool {
90-
layout.size() % PAGE_SIZE == 0 && layout.align() == PAGE_SIZE
90+
layout.size().is_multiple_of(PAGE_SIZE) && layout.align() == PAGE_SIZE
9191
}
9292

9393
/// Allocator using UEFI boot services.

uefi/src/mem/aligned_buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl AlignedBuffer {
100100
/// Check the buffer's alignment against the `required_alignment`.
101101
pub fn check_alignment(&self, required_alignment: usize) -> Result<(), AlignmentError> {
102102
//TODO: use bfr.addr() when it's available
103-
if (self.ptr() as usize) % required_alignment != 0 {
103+
if !(self.ptr() as usize).is_multiple_of(required_alignment) {
104104
return Err(AlignmentError); //TODO: use >is_aligned_to< when it's available
105105
}
106106
Ok(())

uefi/src/proto/hii/config_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl ConfigurationString {
183183
/// An `Option<String>` containing the parsed string.
184184
#[must_use]
185185
pub fn parse_string_from_hex(data: &str) -> Option<String> {
186-
if data.len() % 2 != 0 {
186+
if !data.len().is_multiple_of(2) {
187187
return None;
188188
}
189189
let size_bytes = data.len() / 2 + 2; // includes \0 terminator

uefi/src/proto/loaded_image.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ impl LoadedImage {
7575

7676
if self.0.load_options.is_null() {
7777
Err(LoadOptionsError::NotSet)
78-
} else if (load_options_size % size_of::<u16>() != 0)
79-
|| (((self.0.load_options as usize) % align_of::<u16>()) != 0)
78+
} else if !load_options_size.is_multiple_of(size_of::<u16>())
79+
|| !(self.0.load_options as usize).is_multiple_of(align_of::<u16>())
8080
{
8181
Err(LoadOptionsError::NotAligned)
8282
} else {

0 commit comments

Comments
 (0)