[PATCH 7/8] rust: miscdevice: add `ThisModule` associated type to `MiscDevice` trait

From: Alvin Sun

Date: Tue May 19 2026 - 02:28:23 EST


Add a `ThisModule` associated type bound by `ModuleMetadata` to the
`MiscDevice` trait, and use it to set the miscdevice fops owner field
instead of defaulting to null.

Signed-off-by: Alvin Sun <alvin.sun@xxxxxxxxx>
---
rust/kernel/miscdevice.rs | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs
index 05a6b6b9770f2..007caaae62697 100644
--- a/rust/kernel/miscdevice.rs
+++ b/rust/kernel/miscdevice.rs
@@ -38,6 +38,7 @@
ForeignOwnable,
Opaque, //
},
+ ModuleMetadata, //
};
use core::{
marker::PhantomData,
@@ -137,6 +138,9 @@ pub trait MiscDevice: Sized {
/// What kind of pointer should `Self` be wrapped in.
type Ptr: ForeignOwnable + Send + Sync;

+ /// The module implementing this driver.
+ type ThisModule: ModuleMetadata;
+
/// Called when the misc device is opened.
///
/// The returned pointer will be stored as the private data for the file.
@@ -441,6 +445,7 @@ impl<T: MiscDevice> MiscdeviceVTable<T> {
} else {
None
},
+ owner: <T::ThisModule as ModuleMetadata>::MODULE_PTR,
..pin_init::zeroed()
};


--
2.43.0