Re: [PATCH v2 4/7] rust: drm: set fops.owner from driver module pointer
"Gary Guo" <[email protected]>
| Newsgroups | org.kernel.vger.linux-modules,dev.linux.lists.driver-core,dev.linux.lists.nova-gpu,org.freedesktop.lists.dri-devel,org.kernel.vger.linux-block,org.kernel.vger.linux-kselftest,org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
On Thu May 21, 2026 at 8:52 AM BST, Alvin Sun wrote: > Change `create_fops()` to accept an owner module pointer instead of > hardcoding `null_mut()`, ensuring the kernel correctly tracks the > module owning the DRM device's file operations. > > Signed-off-by: Alvin Sun <[email protected]> > --- > rust/kernel/drm/device.rs | 3 ++- > rust/kernel/drm/gem/mod.rs | 4 ++-- > 2 files changed, 4 insertions(+), 3 deletions(-) > > diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs > index 403fc35353c74..53e44a780ae97 100644 > --- a/rust/kernel/drm/device.rs > +++ b/rust/kernel/drm/device.rs > @@ -111,7 +111,8 @@ impl<T: drm::Driver> Device<T> { > fops: &Self::GEM_FOPS, > }; > > - const GEM_FOPS: bindings::file_operations = drm::gem::create_fops(); > + const GEM_FOPS: bindings::file_operations = > + drm::gem::create_fops(<T::ThisModule as crate::ModuleMetadata>::THIS_MODULE.as_ptr()); I wonder if the assoc type should just be called `Owner` or `OwnerModule`? Best. Gary > > /// Create a new `drm::Device` for a `drm::Driver`. > pub fn new(dev: &device::Device, data: impl PinInit<T::Data, Error>) -> Result<ARef<Self>> { > diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs > index 01b5bd47a3332..9a203efc59116 100644 > --- a/rust/kernel/drm/gem/mod.rs > +++ b/rust/kernel/drm/gem/mod.rs > @@ -357,10 +357,10 @@ impl<T: DriverObject> AllocImpl for Object<T> { > }; > } > > -pub(super) const fn create_fops() -> bindings::file_operations { > +pub(super) const fn create_fops(owner: *mut bindings::module) -> bindings::file_operations { > let mut fops: bindings::file_operations = pin_init::zeroed(); > > - fops.owner = core::ptr::null_mut(); > + fops.owner = owner; > fops.open = Some(bindings::drm_open); > fops.release = Some(bindings::drm_release); > fops.unlocked_ioctl = Some(bindings::drm_ioctl);