Re: [PATCH] rust: Test page_align usize::MAX boundary edges
From: Brendan Shephard
Date: Tue Dec 30 2025 - 04:55:25 EST
On Tue, Dec 30, 2025 at 07:48:41PM +1000, bshephar@xxxxxxxxxxxx wrote:
> From: Brendan Shephard <bshephar@xxxxxxxxxxxx>
>
> Update `page_align` doc tests to test `usize::MAX` boundaries
> rather than arbitrary middle of `PAGE_SIZE`.
>
> This patch is a follow-up of:
> "[PATCH v8] rust: Return Option from page_align and ensure no usize overflow"
>
> Signed-off-by: Brendan Shephard <bshephar@xxxxxxxxxxxx>
> ---
> rust/kernel/page.rs | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/page.rs b/rust/kernel/page.rs
> index adecb200c654..d602d4231f56 100644
> --- a/rust/kernel/page.rs
> +++ b/rust/kernel/page.rs
> @@ -45,9 +45,10 @@
> /// assert_eq!(page_align(0x1), Some(PAGE_SIZE));
> /// assert_eq!(page_align(PAGE_SIZE + 1), Some(2 * PAGE_SIZE));
> ///
> -/// // Requested address causes overflow (returns `None`).
> -/// let overflow_addr = usize::MAX - (PAGE_SIZE / 2);
> -/// assert_eq!(page_align(overflow_addr), None);
> +/// // Testing boundary conditions at the end of the address space.
> +/// assert_eq!(page_align(usize::MAX - PAGE_SIZE + 1), Some(usize::MAX - PAGE_SIZE + 1));
> +/// assert_eq!(page_align(usize::MAX - PAGE_SIZE + 2), None);
> +/// assert_eq!(page_align(usize::MAX), None);
> /// ```
> #[inline(always)]
> pub const fn page_align(addr: usize) -> Option<usize> {
>
> base-commit: 7acc70476f14661149774ab88d3fe23d83ba4249
> --
> 2.52.0
>
@miguel, Thanks for the pointers in:
https://lore.kernel.org/all/CANiq72kcMLXz=xyZeKC0=j_e0BzJEY3wGpBTTxfJsc6EZhCnXA@xxxxxxxxxxxxxx/
https://lore.kernel.org/rust-for-linux/CANiq72mLPvB_6Ow3bW5-V4-km=RyA59chQ1g1x9qUt2P-zZweg@xxxxxxxxxxxxxx/
Let me know if this addresses the points you were raising in those.
Maybe you just wanted usize::MAX and then one over? The first test
case might be unnecessary. The last two do a fine job of illustrating the
point I think.