diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2025-01-20 21:37:39 -0800 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2025-01-20 21:37:39 -0800 |
commit | 25768de50b1f2dbb6ea44bd5148a87fe2c9c3688 (patch) | |
tree | 91f4e0c1ea9acb1e8d477a5f4dfedd00de67ae13 /rust/kernel/page.rs | |
parent | 3a6e5ed2372bcb2a3c554fda32419efd91ff9b0c (diff) | |
parent | 08bd5b7c9a2401faabdaa1472d45c7de0755fd7e (diff) |
Merge branch 'next' into for-linus
Prepare input updates for 6.14 merge window.
Diffstat (limited to 'rust/kernel/page.rs')
-rw-r--r-- | rust/kernel/page.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs index 208a006d587c..fdac6c375fe4 100644 --- a/rust/kernel/page.rs +++ b/rust/kernel/page.rs @@ -20,6 +20,16 @@ pub const PAGE_SIZE: usize = bindings::PAGE_SIZE; /// A bitmask that gives the page containing a given address. pub const PAGE_MASK: usize = !(PAGE_SIZE - 1); +/// Round up the given number to the next multiple of [`PAGE_SIZE`]. +/// +/// It is incorrect to pass an address where the next multiple of [`PAGE_SIZE`] doesn't fit in a +/// [`usize`]. +pub const fn page_align(addr: usize) -> usize { + // Parentheses around `PAGE_SIZE - 1` to avoid triggering overflow sanitizers in the wrong + // cases. + (addr + (PAGE_SIZE - 1)) & PAGE_MASK +} + /// A pointer to a page that owns the page allocation. /// /// # Invariants |