Re: [PATCH v7 4/9] rust: sync: atomic: Add generic atomics
"Benno Lossin" <[email protected]> Mon, 14 Jul 2025 17:16:59 +0200
| Newsgroups | dev.linux.lists.lkmm,org.kernel.vger.linux-arch,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
On Mon Jul 14, 2025 at 4:53 PM CEST, Boqun Feng wrote: > On Mon, Jul 14, 2025 at 04:34:39PM +0200, Miguel Ojeda wrote: >> On Mon, Jul 14, 2025 at 4:22 PM Boqun Feng <[email protected]> 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. I don't think it's necessary to mention the examples below, but this is what I had in mind. --- Cheers, Benno > + /// > /// # 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