Re: [PATCH 1/2] rust: usb: add basic USB abstractions

From: Daniel Almeida
Date: Mon Aug 25 2025 - 17:04:51 EST


Hi Benno,

> On 25 Aug 2025, at 17:49, Benno Lossin <lossin@xxxxxxxxxx> wrote:
>
> On Mon Aug 25, 2025 at 8:18 PM CEST, Daniel Almeida wrote:
>> +impl DeviceId {
>> + /// Equivalent to C's `USB_DEVICE` macro.
>> + pub const fn from_id(vendor: u16, product: u16) -> Self {
>> + Self(bindings::usb_device_id {
>> + 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() }
>
> You can avoid this usage of `unsafe` with this patch series:
>
> https://lore.kernel.org/all/20250814093046.2071971-1-lossin@xxxxxxxxxx
>
> I'd like to avoid introducing any new one of these.
>
> ---
> Cheers,
> Benno
>
>> + })
>> + }
>

Ah, nice, you spoke about this in the last RFL call, I remember it now.

Ok, I will address this in the next version.

— Daniel