From: Siyuan Huang Date: Mon, 20 Oct 2025 03:12:04 +0000 (+0800) Subject: rust: acpi: replace `core::mem::zeroed` with `pin_init::zeroed` X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=040beccb038b7a7dec60ef20383278347a2aa09e;p=thirdparty%2Fkernel%2Flinux.git rust: acpi: 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. Link: https://github.com/Rust-for-Linux/linux/issues/1189 Suggested-by: Benno Lossin Signed-off-by: Siyuan Huang Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin Acked-by: Danilo Krummrich Reviewed-by: Kunwu Chan Link: https://patch.msgid.link/20251020031204.78917-1-huangsiyuan@kylinos.cn Signed-off-by: Rafael J. Wysocki --- diff --git a/rust/kernel/acpi.rs b/rust/kernel/acpi.rs index 37e1161c12985..9b8efa623130c 100644 --- a/rust/kernel/acpi.rs +++ b/rust/kernel/acpi.rs @@ -39,9 +39,7 @@ impl DeviceId { pub const fn new(id: &'static CStr) -> Self { let src = id.to_bytes_with_nul(); build_assert!(src.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes"); - // Replace with `bindings::acpi_device_id::default()` once stabilized for `const`. - // SAFETY: FFI type is valid to be zero-initialized. - let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() }; + let mut acpi: bindings::acpi_device_id = pin_init::zeroed(); let mut i = 0; while i < src.len() { acpi.id[i] = src[i];