rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: auxiliary: use `pin_init::zeroed()` for  device ID
@ 2025-11-29 12:47 Atharv Dubey
  2025-12-01  3:34 ` Alexandre Courbot
  0 siblings, 1 reply; 3+ messages in thread
From: Atharv Dubey @ 2025-11-29 12:47 UTC (permalink / raw)
  To: gregkh, ojeda, alex.gaynor
  Cc: david.m.ertman, ira.weiny, leon, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, dakr, rust-for-linux,
	linux-kernel, 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.

Signed-off-by: Atharv Dubey <atharvd440@gmail.com>
---
 rust/kernel/auxiliary.rs | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs
index 7a3b0b9c418e..67c5d356d754 100644
--- a/rust/kernel/auxiliary.rs
+++ b/rust/kernel/auxiliary.rs
@@ -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() {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: auxiliary: use `pin_init::zeroed()` for  device ID
  2025-11-29 12:47 [PATCH] rust: auxiliary: use `pin_init::zeroed()` for device ID Atharv Dubey
@ 2025-12-01  3:34 ` Alexandre Courbot
  2025-12-01  3:44   ` Alexandre Courbot
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Courbot @ 2025-12-01  3:34 UTC (permalink / raw)
  To: Atharv Dubey, gregkh, ojeda, alex.gaynor
  Cc: david.m.ertman, ira.weiny, leon, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, dakr, rust-for-linux,
	linux-kernel

On Sat Nov 29, 2025 at 9:47 PM JST, Atharv Dubey wrote:
> 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.
>
> Signed-off-by: Atharv Dubey <atharvd440@gmail.com>
> ---
>  rust/kernel/auxiliary.rs | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs
> index 7a3b0b9c418e..67c5d356d754 100644
> --- a/rust/kernel/auxiliary.rs
> +++ b/rust/kernel/auxiliary.rs
> @@ -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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: auxiliary: use `pin_init::zeroed()` for  device ID
  2025-12-01  3:34 ` Alexandre Courbot
@ 2025-12-01  3:44   ` Alexandre Courbot
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Courbot @ 2025-12-01  3:44 UTC (permalink / raw)
  To: Alexandre Courbot, Atharv Dubey, gregkh, ojeda, alex.gaynor
  Cc: david.m.ertman, ira.weiny, leon, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, dakr, rust-for-linux,
	linux-kernel

On Mon Dec 1, 2025 at 12:34 PM JST, Alexandre Courbot wrote:
> On Sat Nov 29, 2025 at 9:47 PM JST, Atharv Dubey wrote:
>> 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.
>>
>> Signed-off-by: Atharv Dubey <atharvd440@gmail.com>
>> ---
>>  rust/kernel/auxiliary.rs | 6 +-----
>>  1 file changed, 1 insertion(+), 5 deletions(-)
>>
>> diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs
>> index 7a3b0b9c418e..67c5d356d754 100644
>> --- a/rust/kernel/auxiliary.rs
>> +++ b/rust/kernel/auxiliary.rs
>> @@ -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.

... 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-01  3:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-29 12:47 [PATCH] rust: auxiliary: use `pin_init::zeroed()` for device ID Atharv Dubey
2025-12-01  3:34 ` Alexandre Courbot
2025-12-01  3:44   ` Alexandre Courbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).