Re: [PATCH] rust: drm: fix unsound initialization in drm::Device::new
From: Gary Guo
Date: Tue Apr 28 2026 - 10:33:41 EST
On Tue Apr 28, 2026 at 1:43 PM BST, Danilo Krummrich wrote:
> On Tue Apr 28, 2026 at 2:20 PM CEST, Eliot Courtney wrote:
>> If pinned initialization of drm::Device::Data fails, it calls
>> drm::Device::release via drm_dev_put. This materializes a reference to
>> &drm::Device, but it's not fully constructed yet, because initializing
>> `data` failed. It should not be dropped either. Instead, if pinned
>> initialization fails, make sure drm::Device::release isn't called.
>>
>> Fixes: 2e9fdbe5ec7a ("rust: drm: device: drop_in_place() the drm::Device in release()")
>> Signed-off-by: Eliot Courtney <ecourtney@xxxxxxxxxx>
>
> There's already a patch from Lyude for this [1].
>
> That said, I like the approach with the ALLOC_VTABLE.
>
> @Lyude: Do you mind if we pick Eliot's patch?
>
> Thanks,
> Danilo
>
> [1] https://lore.kernel.org/lkml/20260320233645.950190-2-lyude@xxxxxxxxxx/
I have to second this and I think this solution is very clean. It does mean
that we're always duplicating vtable though, for just one pointer of difference.
Is it possible to have a shared vtable for drm devices that's in the
allocated-but-not-initialized state?
Best,
Gary