[PATCH v2] rust: sync: add `UniqueArc::as_ptr`

From: Andreas Hindborg

Date: Fri Jun 05 2026 - 09:23:58 EST


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@xxxxxxxxxx>
---
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@xxxxxxxxxx

To: Miguel Ojeda <ojeda@xxxxxxxxxx>
To: Boqun Feng <boqun@xxxxxxxxxx>
To: Gary Guo <gary@xxxxxxxxxxx>
To: Björn Roy Baron <bjorn3_gh@xxxxxxxxxxxxxx>
To: Benno Lossin <lossin@xxxxxxxxxx>
To: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
To: Alice Ryhl <aliceryhl@xxxxxxxxxx>
To: Trevor Gross <tmgross@xxxxxxxxx>
To: Danilo Krummrich <dakr@xxxxxxxxxx>
Cc: rust-for-linux@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
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@xxxxxxxxxx>