All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] rust: sync: add `UniqueArc::as_ptr`
@ 2026-06-05 13:16 Andreas Hindborg
  2026-06-08  7:27 ` Miguel Ojeda
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andreas Hindborg @ 2026-06-05 13:16 UTC (permalink / raw)
  To: Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, Boqun Feng
  Cc: rust-for-linux, linux-kernel, Andreas Hindborg, Boqun Feng

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>
---
Changes in v2:
- Make `UniqueArc::as_ptr` an associated function rather than an inherent method (Benno, Gary).
- Mark `UniqueArc::as_ptr` `#[inline]` (Gary).
- Link to v1: https://msgid.link/20260215-unique-arc-as-ptr-v1-1-bdf4b3174475@kernel.org

To: Miguel Ojeda <ojeda@kernel.org>
To: Boqun Feng <boqun@kernel.org>
To: Gary Guo <gary@garyguo.net>
To: Björn Roy Baron <bjorn3_gh@protonmail.com>
To: Benno Lossin <lossin@kernel.org>
To: Andreas Hindborg <a.hindborg@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
To: Trevor Gross <tmgross@umich.edu>
To: Danilo Krummrich <dakr@kernel.org>
Cc: rust-for-linux@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 rust/kernel/sync/arc.rs | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
index 18d6c0d62ce0..b58549d5f269 100644
--- a/rust/kernel/sync/arc.rs
+++ b/rust/kernel/sync/arc.rs
@@ -756,6 +756,12 @@ 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.
+    #[inline]
+    pub fn as_ptr(this: &Self) -> *const T {
+        Arc::as_ptr(&this.inner)
+    }
 }
 
 impl<T> UniqueArc<MaybeUninit<T>> {

---
base-commit: 7fd2df204f342fc17d1a0bfcd474b24232fb0f32
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 v2] rust: sync: add `UniqueArc::as_ptr`
  2026-06-05 13:16 [PATCH v2] rust: sync: add `UniqueArc::as_ptr` Andreas Hindborg
@ 2026-06-08  7:27 ` Miguel Ojeda
  2026-06-08  8:33   ` Andreas Hindborg
  2026-06-08  7:30 ` Alice Ryhl
  2026-06-08  9:01 ` Miguel Ojeda
  2 siblings, 1 reply; 5+ messages in thread
From: Miguel Ojeda @ 2026-06-08  7:27 UTC (permalink / raw)
  To: Andreas Hindborg
  Cc: Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, Boqun Feng,
	rust-for-linux, linux-kernel

On Fri, Jun 5, 2026 at 3:17 PM Andreas Hindborg <a.hindborg@kernel.org> 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>

Like Sashiko mentions: did you put it in the `<T>` impl for some
reason? Do you want me to move it to a new `?Sized` one?

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rust: sync: add `UniqueArc::as_ptr`
  2026-06-05 13:16 [PATCH v2] rust: sync: add `UniqueArc::as_ptr` Andreas Hindborg
  2026-06-08  7:27 ` Miguel Ojeda
@ 2026-06-08  7:30 ` Alice Ryhl
  2026-06-08  9:01 ` Miguel Ojeda
  2 siblings, 0 replies; 5+ messages in thread
From: Alice Ryhl @ 2026-06-08  7:30 UTC (permalink / raw)
  To: Andreas Hindborg
  Cc: Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin,
	Trevor Gross, Danilo Krummrich, Boqun Feng, rust-for-linux,
	linux-kernel

On Fri, Jun 05, 2026 at 03:16:48PM +0200, 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>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rust: sync: add `UniqueArc::as_ptr`
  2026-06-08  7:27 ` Miguel Ojeda
@ 2026-06-08  8:33   ` Andreas Hindborg
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Hindborg @ 2026-06-08  8:33 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, Boqun Feng,
	rust-for-linux, linux-kernel

Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> writes:

> On Fri, Jun 5, 2026 at 3:17 PM Andreas Hindborg <a.hindborg@kernel.org> 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>
>
> Like Sashiko mentions: did you put it in the `<T>` impl for some
> reason? Do you want me to move it to a new `?Sized` one?

Oversight on my end, this should apply to DST as well. Feel free to move
it, or I can send a new version.

Best regards,
Andreas Hindborg



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rust: sync: add `UniqueArc::as_ptr`
  2026-06-05 13:16 [PATCH v2] rust: sync: add `UniqueArc::as_ptr` Andreas Hindborg
  2026-06-08  7:27 ` Miguel Ojeda
  2026-06-08  7:30 ` Alice Ryhl
@ 2026-06-08  9:01 ` Miguel Ojeda
  2 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2026-06-08  9:01 UTC (permalink / raw)
  To: Andreas Hindborg
  Cc: Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, Boqun Feng,
	rust-for-linux, linux-kernel

On Fri, Jun 5, 2026 at 3:17 PM Andreas Hindborg <a.hindborg@kernel.org> 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>

Applied to `rust-next` -- thanks everyone!

    [ Relaxed bound moving it to new `T: ?Sized` impl block. Reworded since
      it is not a method anymore. Added intra-doc link. - Miguel ]

I used [`UniqueArc`]  since that is what we normally do, even if the
other `as_ptr()` doesn't at the moment.

I opened a "good first issue" with that and another bit I noticed:

  https://github.com/Rust-for-Linux/linux/issues/1240

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-06-08  9:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-05 13:16 [PATCH v2] rust: sync: add `UniqueArc::as_ptr` Andreas Hindborg
2026-06-08  7:27 ` Miguel Ojeda
2026-06-08  8:33   ` Andreas Hindborg
2026-06-08  7:30 ` Alice Ryhl
2026-06-08  9:01 ` Miguel Ojeda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.