From: Brendan Shephard <bshephar@bne-home.net>
To: Alice Ryhl <aliceryhl@google.com>
Cc: miguel.ojeda.sandonis@gmail.com, dakr@kernel.org,
acourbot@nvidia.com, daniel.almeida@collabora.com,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v5] rust: Return Option from page_align and ensure no usize overflow
Date: Tue, 2 Dec 2025 19:37:49 +1000 [thread overview]
Message-ID: <aS6zbbP3BfBE2DJ5@fedora> (raw)
In-Reply-To: <aS1qz6WjjP8E49pY@google.com>
On Mon, Dec 01, 2025 at 10:15:43AM +0000, Alice Ryhl wrote:
> > /// 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
> > +/// Returns a page aligned [`usize`] in cases where the value can be aligned. Otherwise, returns [`None`]
> > +/// if the aligned size will overflow a [`usize`].
>
> The first line of doc-comments is shown on the module docs. I think it'd
> be nice to shorten the first line.
>
> /// Rounds up to the next multiple of [`PAGE_SIZE`].
> ///
> /// Returns `None` on integer overflow.
>
> People reading the module docs will get what they need from "Rounds up
> to the next multiple of PAGE_SIZE.", and if they want to know details
> such as overflow behavior they can read the page specific to this
> method.
>
> Alice
>
>
Seems reasonable, v6 sent with this adjustment:
https://lore.kernel.org/rust-for-linux/aS6y5blasMX0KcD7@fedora/T/#u
Thanks!
Brendan
prev parent reply other threads:[~2025-12-02 9:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 5:45 [PATCH v5] rust: Return Option from page_align and ensure no usize overflow Brendan Shephard
2025-12-01 10:15 ` Alice Ryhl
2025-12-02 9:37 ` Brendan Shephard [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aS6zbbP3BfBE2DJ5@fedora \
--to=bshephar@bne-home.net \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.