Skip to content

Commit 040becc

Browse files
Siyuan Huangrafaeljw
authored andcommitted
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: #1189 Suggested-by: Benno Lossin <lossin@kernel.org> Signed-off-by: Siyuan Huang <huangsiyuan@kylinos.cn> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Acked-by: Danilo Krummrich <dakr@kernel.org> Reviewed-by: Kunwu Chan <chentao@kylinos.cn> Link: https://patch.msgid.link/20251020031204.78917-1-huangsiyuan@kylinos.cn Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent dcb6fa3 commit 040becc

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

rust/kernel/acpi.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ impl DeviceId {
3939
pub const fn new(id: &'static CStr) -> Self {
4040
let src = id.to_bytes_with_nul();
4141
build_assert!(src.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes");
42-
// Replace with `bindings::acpi_device_id::default()` once stabilized for `const`.
43-
// SAFETY: FFI type is valid to be zero-initialized.
44-
let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() };
42+
let mut acpi: bindings::acpi_device_id = pin_init::zeroed();
4543
let mut i = 0;
4644
while i < src.len() {
4745
acpi.id[i] = src[i];

0 commit comments

Comments
 (0)