Re: [PATCH 3/8] rust: drm: add `ThisModule` associated type to `Driver` trait

From: Gary Guo

Date: Tue May 19 2026 - 08:05:25 EST


On Tue May 19, 2026 at 7:26 AM BST, Alvin Sun wrote:
> Add a `ThisModule` associated type bound by `ModuleMetadata` to the
> `drm::Driver` trait, allowing DRM drivers to expose their module
> pointer for use in file operations.

FWIW, I was considering adding this automatically to the `#[vtable]` macro
(associated types/consts won't have any costs if they're unused anyway).

But requiring an explicit specification isn't too bad either.

Best,
Gary

>
> Signed-off-by: Alvin Sun <alvin.sun@xxxxxxxxx>
> ---
> rust/kernel/drm/driver.rs | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs
> index 5233bdebc9fcd..c798961650c1a 100644
> --- a/rust/kernel/drm/driver.rs
> +++ b/rust/kernel/drm/driver.rs
> @@ -115,6 +115,9 @@ pub trait Driver {
>
> /// IOCTL list. See `kernel::drm::ioctl::declare_drm_ioctls!{}`.
> const IOCTLS: &'static [drm::ioctl::DrmIoctlDescriptor];
> +
> + /// The module implementing this driver.
> + type ThisModule: crate::ModuleMetadata;
> }
>
> /// The registration type of a `drm::Device`.