netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 10/13] rust: phy: replace `MaybeUninit::zeroed().assume_init` with `pin_init::zeroed`
       [not found] <20250523145125.523275-1-lossin@kernel.org>
@ 2025-05-23 14:51 ` Benno Lossin
  0 siblings, 0 replies; only message in thread
From: Benno Lossin @ 2025-05-23 14:51 UTC (permalink / raw)
  To: FUJITA Tomonori, Trevor Gross, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Danilo Krummrich
  Cc: Lyude Paul, netdev, rust-for-linux, linux-kernel

All types in `bindings` implement `Zeroable` if they can, so use
`pin_init::zeroed` instead of relying on `unsafe` code.

If this ends up not compiling in the future, something in bindgen or on
the C side changed and is most likely incorrect.

Signed-off-by: Benno Lossin <lossin@kernel.org>
---
 rust/kernel/net/phy.rs | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index a59469c785e3..de38f123e50a 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -563,9 +563,7 @@ pub const fn create_phy_driver<T: Driver>() -> DriverVTable {
         } else {
             None
         },
-        // SAFETY: The rest is zeroed out to initialize `struct phy_driver`,
-        // sets `Option<&F>` to be `None`.
-        ..unsafe { core::mem::MaybeUninit::<bindings::phy_driver>::zeroed().assume_init() }
+        ..pin_init::zeroed()
     }))
 }
 
-- 
2.49.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-05-23 14:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250523145125.523275-1-lossin@kernel.org>
2025-05-23 14:51 ` [PATCH v2 10/13] rust: phy: replace `MaybeUninit::zeroed().assume_init` with `pin_init::zeroed` Benno Lossin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).