[PATCH] rust: of: use safe zero initialization for struct of_device_id

Thorsten Blum posted 1 patch 1 week, 6 days ago
rust/kernel/of.rs | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
[PATCH] rust: of: use safe zero initialization for struct of_device_id
Posted by Thorsten Blum 1 week, 6 days ago
Since bindings::of_device_id implements Zeroable, use pin_init::zeroed()
instead of core::mem::zeroed().

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 rust/kernel/of.rs | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/rust/kernel/of.rs b/rust/kernel/of.rs
index d0318f62afd7..75d5004d2221 100644
--- a/rust/kernel/of.rs
+++ b/rust/kernel/of.rs
@@ -31,9 +31,7 @@ impl DeviceId {
     /// Create a new device id from an OF 'compatible' string.
     pub const fn new(compatible: &'static CStr) -> Self {
         let src = compatible.to_bytes_with_nul();
-        // Replace with `bindings::of_device_id::default()` once stabilized for `const`.
-        // SAFETY: FFI type is valid to be zero-initialized.
-        let mut of: bindings::of_device_id = unsafe { core::mem::zeroed() };
+        let mut of: bindings::of_device_id = pin_init::zeroed();
 
         // TODO: Use `copy_from_slice` once stabilized for `const`.
         let mut i = 0;
Re: [PATCH] rust: of: use safe zero initialization for struct of_device_id
Posted by Miguel Ojeda 1 week, 6 days ago
On Sun, Oct 11, 2026 at 3:24 PM Thorsten Blum <blum@kernel.org> wrote:
>
> Since bindings::of_device_id implements Zeroable, use pin_init::zeroed()
> instead of core::mem::zeroed().
>
> Signed-off-by: Thorsten Blum <blum@kernel.org>

This is:

  https://lore.kernel.org/rust-for-linux/20260828122444.475-1-nils.lehnen@proton.me/

Cc'ing Nils.

Cheers,
Miguel