[PATCH 0/4] rust: pin-init: merge `__init` and `__pinned_init`

From: Gary Guo

Date: Wed Jul 22 2026 - 14:50:58 EST


Currently we have `PinInit::__pinned_init` and `Init::__init` which has
slightly different safety requirement but are required to do the same
thing. Instead of having to duplicate impl everywhere, it's simpler to just
use `Init` as a marker trait that cancels out the pinning requirement on
`PinInit::__pinned_init`. This also simplifies code (and shorten the symbol
name) so `__init` can always be used.

Note that to pull off this change it needs a stage approach. The plan is:
* Patch 1 (the `__pinned_init` and `__init` merge) is to be taken this
cycle through pin-init tree; this preserves the `__pinned_init` method as
an alias for compatibility.
* Patch 2 can be taken via driver-core this cycle.
* Patch 3 (tree-wide changes) to be taken next cycle. I can split this
further up next cycle so this can be routed via various subsystems.
* Patch 4 (removal of `__pinned_init`) is to be taken via pin-init two
cycles after.

---
This might be an opportunity to rethink about the API. IIRC we use `__init`
initially to avoid conflicts because we have the blanket impl on `T` and
`Result<T, E>`.

Maybe we should get rid of the underscores and name it something more
proper, like `init_ptr`, or maybe add an extension trait to raw pointers
type so you can do

unsafe { raw_ptr.init(something_that_impls_pin_init) }

?

To: Benno Lossin <lossin@xxxxxxxxxx>
To: Miguel Ojeda <ojeda@xxxxxxxxxx>
To: Boqun Feng <boqun@xxxxxxxxxx>
To: Björn Roy Baron <bjorn3_gh@xxxxxxxxxxxxxx>
To: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
To: Alice Ryhl <aliceryhl@xxxxxxxxxx>
To: Trevor Gross <tmgross@xxxxxxxxx>
To: Danilo Krummrich <dakr@xxxxxxxxxx>
To: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
To: Tamir Duberstein <tamird@xxxxxxxxxx>
To: Alexandre Courbot <acourbot@xxxxxxxxxx>
To: Onur Özkan <work@xxxxxxxxxxxxx>
Cc: rust-for-linux@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>

---
Gary Guo (4):
rust: pin-init: merge `__pinned_init` and `__init`
rust: devres: use `cast_pin_init` instead of manual reimplementation
rust: treewide: replace `__pinned_init` with `__init`
rust: pin-init: remove `__pinned_init` method for `cfg(kernel)`

rust/kernel/alloc/kbox.rs | 6 +-
rust/kernel/devres.rs | 6 +-
rust/kernel/drm/device.rs | 2 +-
rust/kernel/drm/gpuvm/va.rs | 2 +-
rust/kernel/drm/gpuvm/vm_bo.rs | 2 +-
rust/kernel/init.rs | 10 +--
rust/kernel/pwm.rs | 2 +-
rust/kernel/sync/arc.rs | 4 +-
rust/kernel/types.rs | 2 +-
rust/macros/module.rs | 2 +-
rust/pin-init/examples/mutex.rs | 2 +-
rust/pin-init/examples/static_init.rs | 9 +--
rust/pin-init/src/__internal.rs | 8 +-
rust/pin-init/src/alloc.rs | 6 +-
rust/pin-init/src/lib.rs | 147 ++++++++++++++--------------------
15 files changed, 85 insertions(+), 125 deletions(-)
---
base-commit: b4515cf4156356e8f4fe6e0fdc17f59adab9772f
change-id: 20260722-merge-init-3ed98519ec7f

Best regards,
--
Gary Guo <gary@xxxxxxxxxxx>