[PATCH] rust: drm: Improve safety comment when using `Pin::into_inner_unchecked`

Ewan Chorynski via B4 Relay posted 1 patch 1 month, 2 weeks ago
There is a newer version of this series
rust/kernel/drm/gem/mod.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] rust: drm: Improve safety comment when using `Pin::into_inner_unchecked`
Posted by Ewan Chorynski via B4 Relay 1 month, 2 weeks ago
From: Ewan Chorynski <ewan.chorynski@ik.me>

The safety requirements for `Pin::into_inner_unchecked` state that the
returned pointer must be treated as pinned until it is dropped. Such a
guarantee is provided by the `ARef` type. This patch improve the safety
comment to to better reflect this.

---
Signed-off-by: Ewan Chorynski <ewan.chorynski@ik.me>
---
 rust/kernel/drm/gem/mod.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
index a7f682e95c01..ed11d9c0f427 100644
--- a/rust/kernel/drm/gem/mod.rs
+++ b/rust/kernel/drm/gem/mod.rs
@@ -210,7 +210,7 @@ pub fn new(dev: &drm::Device<T::Driver>, size: usize) -> Result<ARef<Self>> {
         // SAFETY: The arguments are all valid per the type invariants.
         to_result(unsafe { bindings::drm_gem_object_init(dev.as_raw(), obj.obj.get(), size) })?;
 
-        // SAFETY: We never move out of `Self`.
+        // SAFETY: We will never move out of `Self` as `ARef<Self>` is always treated as pinned.
         let ptr = KBox::into_raw(unsafe { Pin::into_inner_unchecked(obj) });
 
         // SAFETY: `ptr` comes from `KBox::into_raw` and hence can't be NULL.

---
base-commit: 6c8e404891e1059564d1a15a71d3d76070304dde
change-id: 20251226-drm-gem-safety-comment-1152e457575f

Best regards,
-- 
Ewan Chorynski <ewan.chorynski@ik.me>
Re: [PATCH] rust: drm: Improve safety comment when using `Pin::into_inner_unchecked`
Posted by Alice Ryhl 1 month, 1 week ago
Thanks for the patch!

On Fri, Dec 26, 2025 at 06:22:36PM +0100, Ewan Chorynski via B4 Relay wrote:
> From: Ewan Chorynski <ewan.chorynski@ik.me>
> 
> The safety requirements for `Pin::into_inner_unchecked` state that the
> returned pointer must be treated as pinned until it is dropped. Such a
> guarantee is provided by the `ARef` type. This patch improve the safety
> comment to to better reflect this.

typo: This patch improves
typo: word "to" is duplicated twice

> ---
> Signed-off-by: Ewan Chorynski <ewan.chorynski@ik.me>

The Signed-off-by needs to go above the --- line. Otherwise it's not
included in the commit message.

Alice