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 <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>
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];