* [PATCH] rust: sync: add `UniqueArc::as_ptr`
@ 2026-02-15 20:38 Andreas Hindborg
2026-02-15 23:26 ` Benno Lossin
2026-02-16 1:38 ` Gary Guo
0 siblings, 2 replies; 5+ messages in thread
From: Andreas Hindborg @ 2026-02-15 20:38 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich
Cc: rust-for-linux, linux-kernel, Andreas Hindborg
Add a method to `UniqueArc` for getting a raw pointer. The implementation
defers to the `Arc` implementation of the same method.
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
rust/kernel/sync/arc.rs | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
index 289f77abf415a..9c70fdd39bd2f 100644
--- a/rust/kernel/sync/arc.rs
+++ b/rust/kernel/sync/arc.rs
@@ -770,6 +770,11 @@ pub fn new_uninit(flags: Flags) -> Result<UniqueArc<MaybeUninit<T>>, AllocError>
inner: unsafe { Arc::from_inner(KBox::leak(inner).into()) },
})
}
+
+ /// Return a raw pointer to the data in this unique arc.
+ pub fn as_ptr(&self) -> *const T {
+ Arc::as_ptr(&self.inner)
+ }
}
impl<T> UniqueArc<MaybeUninit<T>> {
---
base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
change-id: 20260215-unique-arc-as-ptr-32eb209dde1b
Best regards,
--
Andreas Hindborg <a.hindborg@kernel.org>
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] rust: sync: add `UniqueArc::as_ptr`
2026-02-15 20:38 [PATCH] rust: sync: add `UniqueArc::as_ptr` Andreas Hindborg
@ 2026-02-15 23:26 ` Benno Lossin
2026-02-16 7:13 ` Andreas Hindborg
2026-02-16 1:38 ` Gary Guo
1 sibling, 1 reply; 5+ messages in thread
From: Benno Lossin @ 2026-02-15 23:26 UTC (permalink / raw)
To: Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Alice Ryhl, Trevor Gross, Danilo Krummrich
Cc: rust-for-linux, linux-kernel
On Sun Feb 15, 2026 at 9:38 PM CET, Andreas Hindborg wrote:
> Add a method to `UniqueArc` for getting a raw pointer. The implementation
> defers to the `Arc` implementation of the same method.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
> ---
> rust/kernel/sync/arc.rs | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index 289f77abf415a..9c70fdd39bd2f 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -770,6 +770,11 @@ pub fn new_uninit(flags: Flags) -> Result<UniqueArc<MaybeUninit<T>>, AllocError>
> inner: unsafe { Arc::from_inner(KBox::leak(inner).into()) },
> })
> }
> +
> + /// Return a raw pointer to the data in this unique arc.
> + pub fn as_ptr(&self) -> *const T {
This should be an associated function instead of an inherent method.
Cheers,
Benno
> + Arc::as_ptr(&self.inner)
> + }
> }
>
> impl<T> UniqueArc<MaybeUninit<T>> {
>
> ---
> base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
> change-id: 20260215-unique-arc-as-ptr-32eb209dde1b
>
> Best regards,
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust: sync: add `UniqueArc::as_ptr`
2026-02-15 23:26 ` Benno Lossin
@ 2026-02-16 7:13 ` Andreas Hindborg
2026-02-16 10:12 ` Benno Lossin
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Hindborg @ 2026-02-16 7:13 UTC (permalink / raw)
To: Benno Lossin, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Alice Ryhl, Trevor Gross, Danilo Krummrich
Cc: rust-for-linux, linux-kernel
"Benno Lossin" <lossin@kernel.org> writes:
> On Sun Feb 15, 2026 at 9:38 PM CET, Andreas Hindborg wrote:
>> Add a method to `UniqueArc` for getting a raw pointer. The implementation
>> defers to the `Arc` implementation of the same method.
>>
>> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
>> ---
>> rust/kernel/sync/arc.rs | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
>> index 289f77abf415a..9c70fdd39bd2f 100644
>> --- a/rust/kernel/sync/arc.rs
>> +++ b/rust/kernel/sync/arc.rs
>> @@ -770,6 +770,11 @@ pub fn new_uninit(flags: Flags) -> Result<UniqueArc<MaybeUninit<T>>, AllocError>
>> inner: unsafe { Arc::from_inner(KBox::leak(inner).into()) },
>> })
>> }
>> +
>> + /// Return a raw pointer to the data in this unique arc.
>> + pub fn as_ptr(&self) -> *const T {
>
> This should be an associated function instead of an inherent method.
I think this is so that we always call the function on the intended
object rather than going through Deref. Could you please clarify if this
is correct?
Best regards,
Andreas Hindborg
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust: sync: add `UniqueArc::as_ptr`
2026-02-16 7:13 ` Andreas Hindborg
@ 2026-02-16 10:12 ` Benno Lossin
0 siblings, 0 replies; 5+ messages in thread
From: Benno Lossin @ 2026-02-16 10:12 UTC (permalink / raw)
To: Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Alice Ryhl, Trevor Gross, Danilo Krummrich
Cc: rust-for-linux, linux-kernel
On Mon Feb 16, 2026 at 8:13 AM CET, Andreas Hindborg wrote:
> "Benno Lossin" <lossin@kernel.org> writes:
>
>> On Sun Feb 15, 2026 at 9:38 PM CET, Andreas Hindborg wrote:
>>> Add a method to `UniqueArc` for getting a raw pointer. The implementation
>>> defers to the `Arc` implementation of the same method.
>>>
>>> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
>>> ---
>>> rust/kernel/sync/arc.rs | 5 +++++
>>> 1 file changed, 5 insertions(+)
>>>
>>> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
>>> index 289f77abf415a..9c70fdd39bd2f 100644
>>> --- a/rust/kernel/sync/arc.rs
>>> +++ b/rust/kernel/sync/arc.rs
>>> @@ -770,6 +770,11 @@ pub fn new_uninit(flags: Flags) -> Result<UniqueArc<MaybeUninit<T>>, AllocError>
>>> inner: unsafe { Arc::from_inner(KBox::leak(inner).into()) },
>>> })
>>> }
>>> +
>>> + /// Return a raw pointer to the data in this unique arc.
>>> + pub fn as_ptr(&self) -> *const T {
>>
>> This should be an associated function instead of an inherent method.
>
> I think this is so that we always call the function on the intended
> object rather than going through Deref. Could you please clarify if this
> is correct?
If you declare an inherent method on a type that is `Deref` (or
`Receiver`), then you can never call a method with the same name on the
object it derefs to:
struct MyThing;
impl MyThing {
fn as_ptr(&self) -> *const () { /* ... */ }
}
let my_thing = UniqueArc::new(MyThing);
let _: *const MyThing = my_thing.as_ptr(); // this is the method from `UniqueArc`
// to call the other one, we have to write:
let _: *const () = MyThing::my_thing(&*my_thing);
Especially a function with the name `as_ptr` should be associated, since
both very likely return a pointer; this increases the likelihood of
accidentally calling the wrong one.
Cheers,
Benno
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: sync: add `UniqueArc::as_ptr`
2026-02-15 20:38 [PATCH] rust: sync: add `UniqueArc::as_ptr` Andreas Hindborg
2026-02-15 23:26 ` Benno Lossin
@ 2026-02-16 1:38 ` Gary Guo
1 sibling, 0 replies; 5+ messages in thread
From: Gary Guo @ 2026-02-16 1:38 UTC (permalink / raw)
To: Andreas Hindborg
Cc: Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
Alice Ryhl, Trevor Gross, Danilo Krummrich, rust-for-linux,
linux-kernel
On 2026-02-15 20:38, Andreas Hindborg wrote:
> Add a method to `UniqueArc` for getting a raw pointer. The
> implementation
> defers to the `Arc` implementation of the same method.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
> ---
> rust/kernel/sync/arc.rs | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index 289f77abf415a..9c70fdd39bd2f 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -770,6 +770,11 @@ pub fn new_uninit(flags: Flags) ->
> Result<UniqueArc<MaybeUninit<T>>, AllocError>
> inner: unsafe { Arc::from_inner(KBox::leak(inner).into())
> },
> })
> }
> +
> + /// Return a raw pointer to the data in this unique arc.
Please add an `#[inline]` here and make this function not a method.
Best,
Gary
> + pub fn as_ptr(&self) -> *const T {
> + Arc::as_ptr(&self.inner)
> + }
> }
>
> impl<T> UniqueArc<MaybeUninit<T>> {
>
> ---
> base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
> change-id: 20260215-unique-arc-as-ptr-32eb209dde1b
>
> Best regards,
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-02-16 10:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-15 20:38 [PATCH] rust: sync: add `UniqueArc::as_ptr` Andreas Hindborg
2026-02-15 23:26 ` Benno Lossin
2026-02-16 7:13 ` Andreas Hindborg
2026-02-16 10:12 ` Benno Lossin
2026-02-16 1:38 ` Gary Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox