Skip to contentSkip to conversation

rust: acpi: replace manual zero-initialization with `pin_init::zeroed()`

PATCH Superseded Atharv Dubey 2 participants 3 messages Nov 29, 2025 – Dec 1, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
rust/kernel/acpi.rs +1 -3
index 37e1161c1298..9b8efa623130 100644
@@ -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];
Signature · 1 line
2.43.0
#1 lore raw
Quoted 15 lines · Atharv Dubey

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 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
rust/kernel/acpi.rs +0 -0
index 37e1161c1298..9b8efa623130 100644

rust/kernel/acpi.rs impl DeviceId { · line 42

Quoted 4 lines
rust/kernel/acpi.rs +0 -1
@@ -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`.

Let's keep this comment as well.

#2 lore raw
Quoted 24 lines · Alexandre Courbot
Quoted 15 lines · Atharv Dubey

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 | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
rust/kernel/acpi.rs +0 -0
index 37e1161c1298..9b8efa623130 100644

rust/kernel/acpi.rs impl DeviceId { · line 42

Quoted 4 lines
rust/kernel/acpi.rs +0 -1
@@ -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`.

Let's keep this comment as well.

Quoted 2 lines

Sure, will add the comment in V2 of the patch
-Atharv