[PATCH v2] rust_binder: use pin_init::zeroed for file_operations initialization
From: Nicolás Antinori
Date: Thu Jul 02 2026 - 16:58:44 EST
All types in `bindings` implement `Zeroable` if they can. This enables
using `pin_init::zeroed()` for `file_operations` initialization instead
of relying on `unsafe { core::mem::MaybeUninit::zeroed().assume_init() }`.
This change improves readability and removes an unnecessary unsafe
block.
Link: https://github.com/Rust-for-Linux/linux/issues/1189
Suggested-by: Benno Lossin <lossin@xxxxxxxxxx>
Signed-off-by: Nicolás Antinori <nico.antinori.7@xxxxxxxxx>
---
Changelog:
v2: Removed zeroed_ops variable and moved pin_init::zeroed() inside the
struct initialization. This is just a code style change suggested in
the previous patch.
v1: https://lore.kernel.org/rust-for-linux/20260626214404.852685-1-nico.antinori.7@xxxxxxxxx/T/#u
drivers/android/binder/rust_binder_main.rs | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/binder/rust_binder_main.rs
index dc1941cd2407..cc9b10e41807 100644
--- a/drivers/android/binder/rust_binder_main.rs
+++ b/drivers/android/binder/rust_binder_main.rs
@@ -314,9 +314,6 @@ unsafe impl<T> Sync for AssertSync<T> {}
#[no_mangle]
#[used]
pub static rust_binder_fops: AssertSync<kernel::bindings::file_operations> = {
- // SAFETY: All zeroes is safe for the `file_operations` type.
- let zeroed_ops = unsafe { core::mem::MaybeUninit::zeroed().assume_init() };
-
let ops = kernel::bindings::file_operations {
owner: THIS_MODULE.as_ptr(),
poll: Some(rust_binder_poll),
@@ -326,7 +323,7 @@ unsafe impl<T> Sync for AssertSync<T> {}
open: Some(rust_binder_open),
release: Some(rust_binder_release),
flush: Some(rust_binder_flush),
- ..zeroed_ops
+ ..pin_init::zeroed()
};
AssertSync(ops)
};
--
2.47.3