Re: [PATCH v7 4/9] rust: sync: atomic: Add generic atomics

From: Boqun Feng
Date: Mon Jul 14 2025 - 10:54:11 EST


On Mon, Jul 14, 2025 at 04:34:39PM +0200, Miguel Ojeda wrote:
> On Mon, Jul 14, 2025 at 4:22 PM Boqun Feng <boqun.feng@xxxxxxxxx> wrote:
> >
> > Hmm.. why? This is the further information about what the above
> > "Examples" section just mentioned?
>
> I think Benno may be trying to point out is may be confusing what
> "this" may be referring to, i.e. is it referring to something concrete
> about the example, or about `from_ptr` as a whole / in all cases?
>

Ok, how about I do this:

diff --git a/rust/kernel/sync/atomic/generic.rs b/rust/kernel/sync/atomic/generic.rs
index 26d9ff3f7c35..e40010394536 100644
--- a/rust/kernel/sync/atomic/generic.rs
+++ b/rust/kernel/sync/atomic/generic.rs
@@ -135,6 +135,9 @@ pub const fn new(v: T) -> Self {

/// Creates a reference to an atomic `T` from a pointer of `T`.
///
+ /// This usually is used when when communicating with C side or manipulating a C struct, see
+ /// examples below.
+ ///
/// # Safety
///
/// - `ptr` is aligned to `align_of::<T>()`.
@@ -185,9 +188,6 @@ pub const fn new(v: T) -> Self {
/// // no data race.
/// unsafe { Atomic::from_ptr(foo_a_ptr) }.store(2, Release);
/// ```
- ///
- /// However, this should be only used when communicating with C side or manipulating a C
- /// struct.
pub unsafe fn from_ptr<'a>(ptr: *mut T) -> &'a Self
where
T: Sync,

?

Regards,
Boqun

> Cheers,
> Miguel