[PATCH v2] rust: pwm: replace `core::mem::zeroed` with `pin_init::zeroed`

Francis Laniel posted 1 patch 5 days, 12 hours ago
There is a newer version of this series
rust/kernel/pwm.rs | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
[PATCH v2] rust: pwm: replace `core::mem::zeroed` with `pin_init::zeroed`
Posted by Francis Laniel 5 days, 12 hours ago
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.

Link: https://github.com/Rust-for-Linux/linux/issues/1189
Signed-off-by: Francis Laniel <laniel_francis@privacyrequired.com>
Suggested-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Acked-by: Michal Wilczynski <m.wilczynski@samsung.com>
---
 rust/kernel/pwm.rs | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs
index 6c9d667009ef..3427b7d93a03 100644
--- a/rust/kernel/pwm.rs
+++ b/rust/kernel/pwm.rs
@@ -494,9 +494,7 @@ pub(crate) fn as_raw(&self) -> *const bindings::pwm_ops {
 /// This is used to bridge Rust trait implementations to the C `struct pwm_ops`
 /// expected by the kernel.
 pub const fn create_pwm_ops<T: PwmOps>() -> PwmOpsVTable {
-    // SAFETY: `core::mem::zeroed()` is unsafe. For `pwm_ops`, all fields are
-    // `Option<extern "C" fn(...)>` or data, so a zeroed pattern (None/0) is valid initially.
-    let mut ops: bindings::pwm_ops = unsafe { core::mem::zeroed() };
+    let mut ops: bindings::pwm_ops = pin_init::zeroed();
 
     ops.request = Some(Adapter::<T>::request_callback);
     ops.capture = Some(Adapter::<T>::capture_callback);
-- 
2.47.3
Re: [PATCH v2] rust: pwm: replace `core::mem::zeroed` with `pin_init::zeroed`
Posted by Miguel Ojeda 5 days, 12 hours ago
On Tue, Jun 2, 2026 at 4:30 PM Francis Laniel
<laniel_francis@privacyrequired.com> wrote:
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1189
> Signed-off-by: Francis Laniel <laniel_francis@privacyrequired.com>
> Suggested-by: Benno Lossin <lossin@kernel.org>
> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
> Acked-by: Michal Wilczynski <m.wilczynski@samsung.com>

I would suggest this ordering:

    Suggested-by: Benno Lossin <lossin@kernel.org>
    Link: https://github.com/Rust-for-Linux/linux/issues/1189
    Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
    Acked-by: Michal Wilczynski <m.wilczynski@samsung.com>
    Signed-off-by: Francis Laniel <laniel_francis@privacyrequired.com>

I guess this will go through PWM; otherwise, please let me know.

Thanks for the patch!

Cheers,
Miguel