Re: [PATCH 2/8] rust: device: introduce Device::drvdata()

Danilo Krummrich
2025-10-29T15:30:16Z

On Wed Oct 29, 2025 at 1:59 PM CET, Alice Ryhl wrote:
> Are you going to open that docs PR to the Rust compiler about the size
> of TypeID that we talked about? :)

Yes, I will -- thanks for the reminder.

> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
>
>> +// Compile-time checks.
>> +const _: () = {
>> + // Assert that we can `read()` / `write()` a `TypeId` instance from / into `struct driver_type`.
>> + static_assert!(core::mem::size_of::<bindings::driver_type>() == core::mem::size_of::<TypeId>());
>> +};
>
> You don't need the "const _: ()" part. See the definition of
> static_assert! to see why.

Indeed, good catch -- same for the suggestions below.

> Also, I would not require equality. The Rust team did not think that it
> would ever increase in size, but it may decrease.
>
>> /// The core representation of a device in the kernel's driver model.
>> ///
>> /// This structure represents the Rust abstraction for a C `struct device`. A [`Device`] can either
>> @@ -198,12 +204,29 @@ pub unsafe fn as_bound(&self) -> &Device<Bound> {
>> }
>>
>> impl Device<CoreInternal> {
>> + fn type_id_store<T: 'static>(&self) {
>
> This name isn't great. How about "set_type_id()" instead?
>
> Alice