rust: acpi: replace manual zero-initialization with `pin_init::zeroed()`
PATCH v2 1/1 rust: acpi: replace manual zero-initialization with `pin_init::zeroed()`
Use pin_init::zeroed() instead of core::mem::zeroed() for initializing acpi_device_id. This removes an explicit unsafe block and aligns ACPI initialization with the pin-init conversion used across the Rust tree.
--- rust/kernel/acpi.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
rust/kernel/acpi.rs +1 -2
@@ -40,8 +40,7 @@ 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];
Signature · 1 line
2.43.0
Rafael J. Wysocki
maintainerQuoted 7 lines · Atharv Dubey
Use
pin_init::zeroed()instead ofcore::mem::zeroed()for initializingacpi_device_id. This removes an explicit unsafe block and aligns ACPI initialization with the pin-init conversion used across the Rust tree.
A Rust-side ACK or equivalent would be welcome.
Quoted 21 lines
--- rust/kernel/acpi.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)rust/kernel/acpi.rs +1
-3@@ -40,8 +40,7 @@ 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]; --2.43.0
Quoted 10 lines · Rafael J. Wysocki
Quoted 7 lines · Atharv Dubey
Use
pin_init::zeroed()instead ofcore::mem::zeroed()for initializingacpi_device_id. This removes an explicit unsafe block and aligns ACPI initialization with the pin-init conversion used across the Rust tree.A Rust-side ACK or equivalent would be welcome.
Quoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Atharv Dubey
Use
pin_init::zeroed()instead ofcore::mem::zeroed()for initializingacpi_device_id. This removes an explicit unsafe block and aligns ACPI initialization with the pin-init conversion used across the Rust tree.A Rust-side ACK or equivalent would be welcome.
Miguel Ojeda
Acked-byQuoted 2 lines · Rafael J. Wysocki
A Rust-side ACK or equivalent would be welcome.
Cheers,
Miguel