summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorFrancis Laniel <laniel_francis@privacyrequired.com>2026-06-03 19:09:09 +0300
committerUwe Kleine-König <ukleinek@kernel.org>2026-08-11 06:58:48 +0200
commit3aeb2997680ecbce5564b6aa9a56c6d4f1fed209 (patch)
tree2b1411f5a1836f52dd44b044f61a1c6c3c3fba60 /rust
parentd3aca8a2ca5d078a7bc9a3fcb3f418a18a2431a4 (diff)
rust: pwm: replace `core::mem::zeroed` with `pin_init::zeroed`
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. 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> Link: https://patch.msgid.link/20260603160910.159307-1-laniel_francis@privacyrequired.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r--rust/kernel/pwm.rs4
1 files changed, 1 insertions, 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 @@ impl PwmOpsVTable {
/// 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);