Skip to contentSkip to conversation

rust: auxiliary: use `pin_init::zeroed()` for device ID

PATCH In review Atharv Dubey 4 participants 5 messages Nov 29, 2025 – Jan 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: auxiliary: use `pin_init::zeroed()` for device ID

Replace the previous unsafe { core::mem::zeroed() } initialization for bindings::auxillary_device_id with pin_init::zeroed(). This removes the explicit unsafe block and uses the safer pinned zero-initialization helper.

---
 rust/kernel/auxiliary.rs | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
rust/kernel/auxiliary.rs +1 -5
index 7a3b0b9c418e..67c5d356d754 100644
@@ -108,11 +108,7 @@ pub const fn new(modname: &'static CStr, name: &'static CStr) -> Self {
         let name = name.to_bytes_with_nul();
         let modname = modname.to_bytes_with_nul();
 
-        // TODO: Replace with `bindings::auxiliary_device_id::default()` once stabilized for
-        // `const`.
-        //
-        // SAFETY: FFI type is valid to be zero-initialized.
-        let mut id: bindings::auxiliary_device_id = unsafe { core::mem::zeroed() };
+        let mut id: bindings::auxiliary_device_id = pin_init::zeroed();
 
         let mut i = 0;
         while i < modname.len() {
Signature · 1 line
2.43.0
#1 lore raw
Quoted 15 lines · Atharv Dubey

Replace the previous unsafe { core::mem::zeroed() } initialization for bindings::auxillary_device_id with pin_init::zeroed(). This removes the explicit unsafe block and uses the safer pinned zero-initialization helper.

---
 rust/kernel/auxiliary.rs | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
rust/kernel/auxiliary.rs +0 -0
index 7a3b0b9c418e..67c5d356d754 100644

rust/kernel/auxiliary.rs pub const fn new(modname: &'static CStr, name: &'static CStr) -> Self { · line 112

Quoted 5 lines
rust/kernel/auxiliary.rs +0 -2
@@ -108,11 +108,7 @@ pub const fn new(modname: &'static CStr, name: &'static CStr) -> Self {
         let name = name.to_bytes_with_nul();
         let modname = modname.to_bytes_with_nul();
 
-        // TODO: Replace with `bindings::auxiliary_device_id::default()` once stabilized for
-        // `const`.

I'd still keep this TODO, a Default implementation is more adequate that Zeroable here even if they end up doing the same.

Nitpicky: there are two spaces in for device in the patch subject.

#2 lore raw
Quoted 19 lines · Alexandre Courbot
Quoted 18 lines · Atharv Dubey

Replace the previous unsafe { core::mem::zeroed() } initialization for bindings::auxillary_device_id with pin_init::zeroed(). This removes the explicit unsafe block and uses the safer pinned zero-initialization helper.

---
 rust/kernel/auxiliary.rs | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
rust/kernel/auxiliary.rs +0 -0
index 7a3b0b9c418e..67c5d356d754 100644
@@ -108,11 +108,7 @@ pub const fn new(modname: &'static CStr, name: &'static CStr) -> Self {
         let name = name.to_bytes_with_nul();
         let modname = modname.to_bytes_with_nul();
 
Quoted 5 lines

rust/kernel/auxiliary.rs pub const fn new(modname: &'static CStr, name: &'static CStr) -> Self { · line 112

Quoted 2 lines
rust/kernel/auxiliary.rs +0 -2
-        // TODO: Replace with `bindings::auxiliary_device_id::default()` once stabilized for
-        // `const`.

I'd still keep this TODO, a Default implementation is more adequate that Zeroable here even if they end up doing the same.

... or maybe not, after all if a type implements Zeroable this means that all zeroes is a valid initial value for it. Let's see what others think about this.

#3 lore raw
In reply to Atharv Dubey
Quoted 7 lines · Atharv Dubey

Replace the previous unsafe { core::mem::zeroed() } initialization for bindings::auxillary_device_id with pin_init::zeroed(). This removes the explicit unsafe block and uses the safer pinned zero-initialization helper.

These were also sent by Benno, and in the issue he mentions "re-sending", which usually means just adding your Signed-off-by below his:

    https://lore.kernel.org/all/[email protected]/

But he also mentioned the Suggested-by tag etc., so it is probably OK to keep authorship and add:

Cheers,
Miguel

maintainer
#4 lore raw
In reply to Atharv Dubey
Quoted 6 lines · Atharv Dubey

Replace the previous unsafe { core::mem::zeroed() } initialization for bindings::auxillary_device_id with pin_init::zeroed(). This removes the explicit unsafe block and uses the safer pinned zero-initialization helper.

Applied to driver-core-testing, thanks!