rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: Alexandre Courbot <acourbot@nvidia.com>
Cc: Brendan Shephard <bshephar@bne-home.net>,
	dakr@kernel.org, airlied@gmail.com,  aliceryhl@google.com,
	rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: Return Option from page_align and ensure no usize overflow
Date: Fri, 28 Nov 2025 03:12:13 +0100	[thread overview]
Message-ID: <CANiq72kiscT5euAUjcSzvxMzM9Hdj8aQGeUN_pVF-vHf3DhBuQ@mail.gmail.com> (raw)
In-Reply-To: <DEJWIFG5Y65B.17EZVKB63RUJ1@nvidia.com>

On Fri, Nov 28, 2025 at 1:29 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>
> Ah, indeed. In that case, can we make the if arms symmetric:
>
>     if let Some(sum) = addr.checked_add(PAGE_SIZE - 1) {
>         Some(sum & PAGE_MASK);
>     } else {
>         None
>     }

Early return style makes the happy path less indented and is more
consistent with the C side. However, here the happy case would be the
indented case, so `let else` would be better:

    let Some(sum) = addr.checked_add(PAGE_SIZE - 1) else {
        return None;
    };

    Some(sum & PAGE_MASK)

Cheers,
Miguel

  reply	other threads:[~2025-11-28  2:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27 13:07 [PATCH] rust: Return Option from page_align and ensure no usize overflow Brendan Shephard
2025-11-27 13:42 ` Alexandre Courbot
2025-11-27 14:18   ` Brendan Shephard
2025-11-28  0:28     ` Alexandre Courbot
2025-11-28  2:12       ` Miguel Ojeda [this message]
2025-11-28  5:29         ` Brendan Shephard
2025-11-28  6:51           ` Alexandre Courbot
2025-11-28  9:09             ` Alice Ryhl
2025-11-28 13:34               ` Alexandre Courbot
2025-11-27 13:44 ` Daniel Almeida
2025-11-27 14:21   ` Brendan Shephard
2025-11-27 14:40 ` [PATCH v2] " Brendan Shephard
2025-11-27 16:24   ` Miguel Ojeda
2025-11-28  3:35     ` Brendan Shephard

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=CANiq72kiscT5euAUjcSzvxMzM9Hdj8aQGeUN_pVF-vHf3DhBuQ@mail.gmail.com \
    --to=miguel.ojeda.sandonis@gmail.com \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bshephar@bne-home.net \
    --cc=dakr@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).