[PATCH v2 3/7] rust: drm: move file_operations from gem to device

From: Danilo Krummrich

Date: Fri Nov 06 2026 - 21:22:33 EST


Move the file_operations definition from drm::gem::create_fops() into
UnregisteredDevice in drm::device. This is the file_operations of the
DRM minor device, set through the drm_driver struct. It is not specific
to GEM.

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Reviewed-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
---
rust/kernel/drm/device.rs | 23 ++++++++++++++++++++---
rust/kernel/drm/gem/mod.rs | 20 --------------------
2 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
index dd1c83fef323..3340fa0dc46b 100644
--- a/rust/kernel/drm/device.rs
+++ b/rust/kernel/drm/device.rs
@@ -195,11 +195,28 @@ const fn compute_features() -> u32 {
driver_features: Self::compute_features(),
ioctls: T::IOCTLS.as_ptr(),
num_ioctls: T::IOCTLS.len() as i32,
- fops: &Self::GEM_FOPS,
+ fops: &Self::FOPS,
};

- const GEM_FOPS: bindings::file_operations =
- drm::gem::create_fops(crate::module::this_module::<T::OwnerModule>().as_ptr());
+ const FOPS: bindings::file_operations = {
+ let mut fops: bindings::file_operations = pin_init::zeroed();
+
+ fops.owner = crate::module::this_module::<T::OwnerModule>().as_ptr();
+ fops.open = Some(bindings::drm_open);
+ fops.release = Some(bindings::drm_release);
+ fops.unlocked_ioctl = Some(bindings::drm_ioctl);
+ #[cfg(CONFIG_COMPAT)]
+ {
+ fops.compat_ioctl = Some(bindings::drm_compat_ioctl);
+ }
+ fops.poll = Some(bindings::drm_poll);
+ fops.read = Some(bindings::drm_read);
+ fops.llseek = Some(bindings::noop_llseek);
+ fops.mmap = Some(bindings::drm_gem_mmap);
+ fops.fop_flags = bindings::FOP_UNSIGNED_OFFSET;
+
+ fops
+ };

/// Create a new `UnregisteredDevice` for a `drm::Driver`.
///
diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
index 94355081edab..260f36817f96 100644
--- a/rust/kernel/drm/gem/mod.rs
+++ b/rust/kernel/drm/gem/mod.rs
@@ -388,23 +388,3 @@ impl<T: DriverObject, Ctx: DeviceContext> AllocImpl for Object<T, Ctx> {
dumb_map_offset: None,
};
}
-
-pub(super) const fn create_fops(owner: *mut bindings::module) -> bindings::file_operations {
- let mut fops: bindings::file_operations = pin_init::zeroed();
-
- fops.owner = owner;
- fops.open = Some(bindings::drm_open);
- fops.release = Some(bindings::drm_release);
- fops.unlocked_ioctl = Some(bindings::drm_ioctl);
- #[cfg(CONFIG_COMPAT)]
- {
- fops.compat_ioctl = Some(bindings::drm_compat_ioctl);
- }
- fops.poll = Some(bindings::drm_poll);
- fops.read = Some(bindings::drm_read);
- fops.llseek = Some(bindings::noop_llseek);
- fops.mmap = Some(bindings::drm_gem_mmap);
- fops.fop_flags = bindings::FOP_UNSIGNED_OFFSET;
-
- fops
-}
--
2.56.0