Skip to content

Commit ab7159c

Browse files
committed
build: Replace manual division with div_ceil
Signed-off-by: Akira Moroo <[email protected]>
1 parent ef9cc7f commit ab7159c

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

src/efi/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Allocator {
4242
}
4343

4444
pub fn page_count(&self, size: usize) -> u64 {
45-
((size + self.page_size as usize - 1) / self.page_size as usize) as u64
45+
size.div_ceil(self.page_size as usize) as u64
4646
}
4747

4848
// Assume called in order with non-overlapping sections.
@@ -338,7 +338,7 @@ impl Allocator {
338338
}
339339

340340
pub fn allocate_pool(&mut self, memory_type: MemoryType, size: usize) -> (Status, u64) {
341-
let page_count = (size as u64 + self.page_size - 1) / self.page_size;
341+
let page_count = (size as u64).div_ceil(self.page_size);
342342
let (status, address) =
343343
self.allocate_pages(efi::ALLOCATE_ANY_PAGES, memory_type, page_count, 0);
344344

src/fat.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,7 @@ impl<'a> Filesystem<'a> {
665665
self.bytes_per_sector = u32::from(h.bytes_per_sector);
666666
self.fat_count = u32::from(h.fat_count);
667667
self.sectors_per_cluster = u32::from(h.sectors_per_cluster);
668-
self.root_dir_sectors = ((u32::from(h.root_dir_count * 32)) + self.bytes_per_sector - 1)
669-
/ self.bytes_per_sector;
668+
self.root_dir_sectors = (u32::from(h.root_dir_count * 32)).div_ceil(self.bytes_per_sector);
670669

671670
self.sectors_per_fat = if h.legacy_sectors_per_fat == 0 {
672671
let h32 = unsafe { &*(data.as_bytes().as_ptr() as *const Fat32Header) };

src/pci.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ where
176176
}
177177

178178
fn naturally_align(address: u64, size: u64) -> u64 {
179-
((address + size - 1) / size) * size
179+
address.div_ceil(size) * size
180180
}
181181

182182
#[derive(Default)]

0 commit comments

Comments
 (0)