History

rust_binder: use pin_init::zeroed for file_operations initialization

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.

Nicolás Antinori committed 4 months ago

Commit 5d577fa1 parent 4b17dfb1 file · +1 −4Browse files

Unified · Split

drivers/android/binder/rust_binder_main.rs+1−4
@@ -324,9 +324,6 @@ unsafe impl<T> Sync for AssertSync<T> {} · 323 unmodified lines
324324 #[no_mangle]
325325 #[used]
326326 pub static rust_binder_fops: AssertSync<kernel::bindings::file_operations> = {
327− // SAFETY: All zeroes is safe for the `file_operations` type.
328− let zeroed_ops = unsafe { core::mem::MaybeUninit::zeroed().assume_init() };
329−
330327 let ops = kernel::bindings::file_operations {
331328 owner: THIS_MODULE.as_ptr(),
332329 poll: Some(rust_binder_poll),
@@ -336,7 +333,7 @@ pub static rust_binder_fops: AssertSync<kernel::bindings::file_operations> = { · 3 unmodified lines
336333 open: Some(rust_binder_open),
337334 release: Some(rust_binder_release),
338335 flush: Some(rust_binder_flush),
339− ..zeroed_ops
336+ ..pin_init::zeroed()
340337 };
341338 AssertSync(ops)
342339 };