From: "Gary Guo" <gary@garyguo.net>
To: "Sagar Taunk" <sagartaunk2@gmail.com>, <ojeda@kernel.org>
Cc: <boqun@kernel.org>, <lossin@kernel.org>, <tmgross@umich.edu>,
<dakr@kernel.org>, <aliceryhl@google.com>,
<bjorn3_gh@protonmail.com>, <gary@garyguo.net>,
<a.hindborg@kernel.org>, <rust-for-linux@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] rust: sync: atomic: clarify AtomicAdd safety comment
Date: Tue, 28 Apr 2026 00:04:13 +0100 [thread overview]
Message-ID: <DI4B9XZCLDBJ.1GNF26UE7NMQY@garyguo.net> (raw)
In-Reply-To: <20260427203258.22148-1-sagartaunk2@gmail.com>
On Mon Apr 27, 2026 at 9:32 PM BST, Sagar Taunk wrote:
> The previous safety comment for AtomicAdd was marked with a TODO
> and contained a grammatically broken sentence that was difficult to
> parse. Rewrite the safety requirement to clearly state the actual
> contract: calling wrapping_add with a delta from rhs_into_delta()
> on a repr obtained via into_repr() from a valid Self must produce
> a bit pattern valid for Self.
Where's patch 1/2?
>
> Signed-off-by: Sagar Taunk <sagartaunk2@gmail.com>
> ---
> rust/kernel/sync/atomic.rs | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/rust/kernel/sync/atomic.rs b/rust/kernel/sync/atomic.rs
> index 9cd009d57e35..b38d9a17f9e8 100644
> --- a/rust/kernel/sync/atomic.rs
> +++ b/rust/kernel/sync/atomic.rs
> @@ -127,10 +127,9 @@ pub unsafe trait AtomicType: Sized + Copy {
> ///
> /// # Safety
> ///
> -// TODO: Properly defines `wrapping_add` in the following comment.
> -/// `wrapping_add` any value of type `Self::Repr::Delta` obtained by [`Self::rhs_into_delta()`] to
> -/// any value of type `Self::Repr` obtained through transmuting a value of type `Self` to must
> -/// yield a value with a bit pattern also valid for `Self`.
> +/// Calling `wrapping_add` with any value of type `Self::Repr::Delta` produced by
It does not read to me there's any clarification being done here.
Best,
Gary
> +/// `Self::rhs_into_delta()`, on any `Self::Repr` value obtained via `into_repr()` from a valid
> +/// `Self`, must produce a bit pattern also valid for `Self`.
> pub unsafe trait AtomicAdd<Rhs = Self>: AtomicType {
> /// Converts `Rhs` into the `Delta` type of the atomic implementation.
> fn rhs_into_delta(rhs: Rhs) -> <Self::Repr as AtomicImpl>::Delta;
next prev parent reply other threads:[~2026-04-27 23:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 20:32 [PATCH 2/2] rust: sync: atomic: clarify AtomicAdd safety comment Sagar Taunk
2026-04-27 23:04 ` Gary Guo [this message]
2026-04-28 3:39 ` [PATCH v2] " Sagar Taunk
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=DI4B9XZCLDBJ.1GNF26UE7NMQY@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sagartaunk2@gmail.com \
--cc=tmgross@umich.edu \
/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