Skip to contentSkip to conversation

rust: drm: use `pin_init::zeroed()` for file operations initialization

PATCH In review Atharv Dubey 4 participants 4 messages Dec 1, 2025 – Dec 2, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rust: drm: use `pin_init::zeroed()` for file operations initialization

Replace the manual unsafe { core::mem::zeroed() } initialization of bindings::file_operations with pin_init::zeroed(). This removes the explicit unsafe

---
 rust/kernel/drm/gem/mod.rs | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
rust/kernel/drm/gem/mod.rs +1 -3
index 30c853988b94..f9fd98dc102b 100644
@@ -298,9 +298,7 @@ impl<T: DriverObject> AllocImpl for Object<T> {
 }
 
 pub(super) const fn create_fops() -> bindings::file_operations {
-    // SAFETY: As by the type invariant, it is safe to initialize `bindings::file_operations`
-    // zeroed.
-    let mut fops: bindings::file_operations = unsafe { core::mem::zeroed() };
+    let mut fops: bindings::file_operations = pin_init::zeroed();
 
     fops.owner = core::ptr::null_mut();
     fops.open = Some(bindings::drm_open);
Signature · 1 line
2.43.0
#1 lore raw

Hi Atharv,

Quoted 30 lines · Atharv Dubey

Replace the manual unsafe { core::mem::zeroed() } initialization of bindings::file_operations with pin_init::zeroed(). This removes the explicit unsafe

---
rust/kernel/drm/gem/mod.rs | 4 +---

1 file changed, 1 insertion(+), 3 deletions(-)
rust/kernel/drm/gem/mod.rs +1 -3
index 30c853988b94..f9fd98dc102b 100644
@@ -298,9 +298,7 @@ impl<T: DriverObject> AllocImpl for Object<T> {
 }
 
 pub(super) const fn create_fops() -> bindings::file_operations {
-    // SAFETY: As by the type invariant, it is safe to initialize `bindings::file_operations`
-    // zeroed.
-    let mut fops: bindings::file_operations = unsafe { core::mem::zeroed() };
+    let mut fops: bindings::file_operations = pin_init::zeroed();
 
    fops.owner = core::ptr::null_mut();
    fops.open = Some(bindings::drm_open);
Signature · 1 line
2.43.0

I wonder if this should be part of a larger series that implements this change throughout the tree?

— Daniel

#2 lore raw
Quoted 3 lines · Daniel Almeida

I wonder if this should be part of a larger series that implements this change throughout the tree?

They are independent, so it is easier to land them as such (and may be clearer that is the case by sending them separately), but having them in a series (even if landed separately) is also OK.

Cheers,
Miguel

maintainer
#3 lore raw
In reply to Atharv Dubey
Quoted 5 lines · Atharv Dubey

Replace the manual unsafe { core::mem::zeroed() } initialization of bindings::file_operations with pin_init::zeroed(). This removes the explicit unsafe

Thanks, I'll pick this up for drm-rust-next once the branch reopens in two weeks.

Alice