* [PATCH] usb: rust: Use pin_init::zeroed for usb_device_id initialization
@ 2026-06-25 22:49 Nicolás Antinori
2026-06-26 6:19 ` Alexandre Courbot
2026-06-28 10:08 ` Miguel Ojeda
0 siblings, 2 replies; 4+ messages in thread
From: Nicolás Antinori @ 2026-06-25 22:49 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Nicolás Antinori, Alexandre Courbot, Alice Ryhl,
Miguel Ojeda, Andreas Hindborg, Benno Lossin,
Björn Roy Baron, Boqun Feng, Daniel Almeida,
Danilo Krummrich, Gary Guo, Onur Özkan, Shuah Khan,
Tamir Duberstein, Trevor Gross, linux-kernel, linux-usb,
rust-for-linux, linux-kernel-mentees
All types in `bindings` implement `Zeroable` if they can. This enables
using `pin_init::zeroed()` for `usb_device_id` initialization instead
of relying on `..unsafe { MaybeUninit::zeroed().assume_init() }`.
This change improves readability and removes unnecessary unsafe blocks.
Link: https://github.com/Rust-for-Linux/linux/issues/1189
Suggested-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
---
rust/kernel/usb.rs | 31 ++++++++++---------------------
1 file changed, 10 insertions(+), 21 deletions(-)
diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs
index 7aff0c82d0af..bbf85366d2c9 100644
--- a/rust/kernel/usb.rs
+++ b/rust/kernel/usb.rs
@@ -24,11 +24,8 @@
};
use core::{
marker::PhantomData,
- mem::{
- offset_of,
- MaybeUninit, //
- },
- ptr::NonNull,
+ mem::offset_of,
+ ptr::NonNull, //
};
/// An adapter for the registration of USB drivers.
@@ -130,8 +127,7 @@ pub const fn from_id(vendor: u16, product: u16) -> Self {
match_flags: bindings::USB_DEVICE_ID_MATCH_DEVICE as u16,
idVendor: vendor,
idProduct: product,
- // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`.
- ..unsafe { MaybeUninit::zeroed().assume_init() }
+ ..pin_init::zeroed()
})
}
@@ -143,8 +139,7 @@ pub const fn from_device_ver(vendor: u16, product: u16, bcd_lo: u16, bcd_hi: u16
idProduct: product,
bcdDevice_lo: bcd_lo,
bcdDevice_hi: bcd_hi,
- // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`.
- ..unsafe { MaybeUninit::zeroed().assume_init() }
+ ..pin_init::zeroed()
})
}
@@ -155,8 +150,7 @@ pub const fn from_device_info(class: u8, subclass: u8, protocol: u8) -> Self {
bDeviceClass: class,
bDeviceSubClass: subclass,
bDeviceProtocol: protocol,
- // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`.
- ..unsafe { MaybeUninit::zeroed().assume_init() }
+ ..pin_init::zeroed()
})
}
@@ -167,8 +161,7 @@ pub const fn from_interface_info(class: u8, subclass: u8, protocol: u8) -> Self
bInterfaceClass: class,
bInterfaceSubClass: subclass,
bInterfaceProtocol: protocol,
- // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`.
- ..unsafe { MaybeUninit::zeroed().assume_init() }
+ ..pin_init::zeroed()
})
}
@@ -180,8 +173,7 @@ pub const fn from_device_interface_class(vendor: u16, product: u16, class: u8) -
idVendor: vendor,
idProduct: product,
bInterfaceClass: class,
- // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`.
- ..unsafe { MaybeUninit::zeroed().assume_init() }
+ ..pin_init::zeroed()
})
}
@@ -193,8 +185,7 @@ pub const fn from_device_interface_protocol(vendor: u16, product: u16, protocol:
idVendor: vendor,
idProduct: product,
bInterfaceProtocol: protocol,
- // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`.
- ..unsafe { MaybeUninit::zeroed().assume_init() }
+ ..pin_init::zeroed()
})
}
@@ -206,8 +197,7 @@ pub const fn from_device_interface_number(vendor: u16, product: u16, number: u8)
idVendor: vendor,
idProduct: product,
bInterfaceNumber: number,
- // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`.
- ..unsafe { MaybeUninit::zeroed().assume_init() }
+ ..pin_init::zeroed()
})
}
@@ -227,8 +217,7 @@ pub const fn from_device_and_interface_info(
bInterfaceClass: class,
bInterfaceSubClass: subclass,
bInterfaceProtocol: protocol,
- // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`.
- ..unsafe { MaybeUninit::zeroed().assume_init() }
+ ..pin_init::zeroed()
})
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: rust: Use pin_init::zeroed for usb_device_id initialization
2026-06-25 22:49 [PATCH] usb: rust: Use pin_init::zeroed for usb_device_id initialization Nicolás Antinori
@ 2026-06-26 6:19 ` Alexandre Courbot
2026-06-28 10:08 ` Miguel Ojeda
1 sibling, 0 replies; 4+ messages in thread
From: Alexandre Courbot @ 2026-06-26 6:19 UTC (permalink / raw)
To: Nicolás Antinori
Cc: Greg Kroah-Hartman, Alice Ryhl, Miguel Ojeda, Andreas Hindborg,
Benno Lossin, Björn Roy Baron, Boqun Feng, Daniel Almeida,
Danilo Krummrich, Gary Guo, Onur Özkan, Shuah Khan,
Tamir Duberstein, Trevor Gross, linux-kernel, linux-usb,
rust-for-linux, linux-kernel-mentees
On Fri Jun 26, 2026 at 7:49 AM JST, Nicolás Antinori wrote:
> All types in `bindings` implement `Zeroable` if they can. This enables
> using `pin_init::zeroed()` for `usb_device_id` initialization instead
> of relying on `..unsafe { MaybeUninit::zeroed().assume_init() }`.
>
> This change improves readability and removes unnecessary unsafe blocks.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1189
> Suggested-by: Benno Lossin <lossin@kernel.org>
> Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: rust: Use pin_init::zeroed for usb_device_id initialization
2026-06-25 22:49 [PATCH] usb: rust: Use pin_init::zeroed for usb_device_id initialization Nicolás Antinori
2026-06-26 6:19 ` Alexandre Courbot
@ 2026-06-28 10:08 ` Miguel Ojeda
2026-07-08 12:10 ` Greg Kroah-Hartman
1 sibling, 1 reply; 4+ messages in thread
From: Miguel Ojeda @ 2026-06-28 10:08 UTC (permalink / raw)
To: Nicolás Antinori
Cc: Greg Kroah-Hartman, Alexandre Courbot, Alice Ryhl, Miguel Ojeda,
Andreas Hindborg, Benno Lossin, Björn Roy Baron, Boqun Feng,
Daniel Almeida, Danilo Krummrich, Gary Guo, Onur Özkan,
Shuah Khan, Tamir Duberstein, Trevor Gross, linux-kernel,
linux-usb, rust-for-linux, linux-kernel-mentees
On Fri, Jun 26, 2026 at 12:50 AM Nicolás Antinori
<nico.antinori.7@gmail.com> wrote:
>
> All types in `bindings` implement `Zeroable` if they can. This enables
> using `pin_init::zeroed()` for `usb_device_id` initialization instead
> of relying on `..unsafe { MaybeUninit::zeroed().assume_init() }`.
>
> This change improves readability and removes unnecessary unsafe blocks.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1189
> Suggested-by: Benno Lossin <lossin@kernel.org>
> Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
Looks fine -- if needed I can pick it up via `rust-next`.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: rust: Use pin_init::zeroed for usb_device_id initialization
2026-06-28 10:08 ` Miguel Ojeda
@ 2026-07-08 12:10 ` Greg Kroah-Hartman
0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2026-07-08 12:10 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nicolás Antinori, Alexandre Courbot, Alice Ryhl,
Miguel Ojeda, Andreas Hindborg, Benno Lossin,
Björn Roy Baron, Boqun Feng, Daniel Almeida,
Danilo Krummrich, Gary Guo, Onur Özkan, Shuah Khan,
Tamir Duberstein, Trevor Gross, linux-kernel, linux-usb,
rust-for-linux, linux-kernel-mentees
On Sun, Jun 28, 2026 at 12:08:56PM +0200, Miguel Ojeda wrote:
> On Fri, Jun 26, 2026 at 12:50 AM Nicolás Antinori
> <nico.antinori.7@gmail.com> wrote:
> >
> > All types in `bindings` implement `Zeroable` if they can. This enables
> > using `pin_init::zeroed()` for `usb_device_id` initialization instead
> > of relying on `..unsafe { MaybeUninit::zeroed().assume_init() }`.
> >
> > This change improves readability and removes unnecessary unsafe blocks.
> >
> > Link: https://github.com/Rust-for-Linux/linux/issues/1189
> > Suggested-by: Benno Lossin <lossin@kernel.org>
> > Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
>
> Looks fine -- if needed I can pick it up via `rust-next`.
I'll take it, thanks.
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-08 12:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-25 22:49 [PATCH] usb: rust: Use pin_init::zeroed for usb_device_id initialization Nicolás Antinori
2026-06-26 6:19 ` Alexandre Courbot
2026-06-28 10:08 ` Miguel Ojeda
2026-07-08 12:10 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox