From: Brendan Shephard <bshephar@bne-home.net>
To: Alexandre Courbot <acourbot@nvidia.com>
Cc: aliceryhl@google.com, miguel.ojeda.sandonis@gmail.com,
dakr@kernel.org, daniel.almeida@collabora.com,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v7] rust: Return Option from page_align and ensure no usize overflow
Date: Tue, 23 Dec 2025 16:03:39 +1000 [thread overview]
Message-ID: <aUowuzq9bTV1nYrn@fedora> (raw)
In-Reply-To: <DF1DAR4ZZ9KG.3UE6JTJOOMULO@nvidia.com>
On Thu, Dec 18, 2025 at 10:13:23PM +0900, Alexandre Courbot wrote:
> On Fri Dec 5, 2025 at 7:40 AM JST, Brendan Shephard wrote:
> > +/// Returns [`None`] on integer overflow.
> > +///
> > +/// # Examples
> > +///
> > +/// ```
> > +/// use kernel::page::{page_align, PAGE_SIZE};
>
> Add an extra line to separate the imports from the code.
>
> > +/// // Requested address is already aligned
>
> Please consistently finish sentences with a `.`.
>
> > +/// assert_eq!(page_align(0x0), Some(0x0));
> > +/// assert_eq!(page_align(PAGE_SIZE), Some(PAGE_SIZE));
> > +///
> > +/// // Requested address needs alignment up
> > +/// 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)
> > +/// // The check asserts that `None` is returned when a value is requested within one `PAGE_SIZE` of
> > +/// // `usize::MAX`.
>
> We can see what the check does by looking at it, so this last sentence
> feels heavy and unnecessary.
>
> > +/// let overflow_addr = usize::MAX - (PAGE_SIZE / 2);
> > +/// assert_eq!(page_align(overflow_addr), None);
> > +///
> > +/// // Requested address of `usize::MAX` would overflow, and subsequently returns `None`.
> > +/// assert_eq!(page_align(usize::MAX), None);
>
> This test is basically equivalent to the previous one and can be
> discarded imho.
>
> I have checked the tests and rustdoc fwiw, and saw no issue, so this
> looks good to go after these last details are fixed.
>
>
Yeah, sounds good. I fixed up those and sent a new revision:
https://lore.kernel.org/rust-for-linux/20251223055647.9761-1-bshephar@bne-home.net/T/#u
Thanks again! Hope you enjoy your holidays.
prev parent reply other threads:[~2025-12-23 6:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-04 22:40 [PATCH v7] rust: Return Option from page_align and ensure no usize overflow Brendan Shephard
2025-12-18 13:13 ` Alexandre Courbot
2025-12-23 6:03 ` 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=aUowuzq9bTV1nYrn@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox