Re: [PATCH] rust: miscdevice: add registration data to MiscDevice

From: Gary Guo

Date: Sun Aug 09 2026 - 07:50:29 EST


On Sat Aug 8, 2026 at 2:53 PM BST, Alice Ryhl wrote:
> On Fri, Aug 07, 2026 at 04:48:53PM +0100, Gary Guo wrote:
>> On Fri Aug 7, 2026 at 4:44 PM BST, Alice Ryhl wrote:
>> > On Fri, Aug 7, 2026 at 4:43 PM Gary Guo <gary@xxxxxxxxxxx> wrote:
>> >>
>> >> On Fri Aug 7, 2026 at 3:22 PM BST, Alice Ryhl wrote:
>> >> > impl<T: MiscDevice> MiscDeviceRegistration<T> {
>> >> > /// Register a misc device.
>> >> > - pub fn register(opts: MiscDeviceOptions) -> impl PinInit<Self, Error> {
>> >> > + pub fn register(
>> >> > + opts: MiscDeviceOptions,
>> >> > + data: impl PinInit<T::RegistrationData, Error>,
>> >>
>> >> We can just skip the `RegistrationData` and use `T`?
>> >
>> > `T` is the type of the data stored per-fd. We do not separate types
>> > for those two concepts.
>>
>> This is getting backwards though, and won't work when we need to introduce
>> lifetimes.
>>
>> Per-fd data needs to be able to reference whatever lifetime is available on
>> per-reg data, so it should be assoc type of the per-reg data type. The way
>> around you current have causes `T::RegistrationData` to be able to reference
>> lifetimes on `T` which is not okay and would only work with `'static` data.
>
> Unfortunately the fds can outlive the registration, so we can't have
> such lifetimes to begin with.
>
> I know that miscdevice isn't currently built to work with the new device
> model. We should fix that, but it is out of scope for this patch. Until
> then, I think the current solution in this patch is sufficient.

For course material we should try to teach the new device model. Yes without a
proper revocation mechanism the fd data cannot have lifetimes, but we can
workaround that by having `type Data: 'static` for now.

Best,
Gary