[PATCH 2/2] rust: drm: gem: Add ObjectFile type alias
Lyude Paul
lyude at redhat.com
Thu May 15 21:42:38 UTC 2025
Just to reduce the clutter with the File<…> types in gem.rs.
Signed-off-by: Lyude Paul <lyude at redhat.com>
---
rust/kernel/drm/gem/mod.rs | 34 ++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
index ffd45419d563a..b1f2bd4aa8cf8 100644
--- a/rust/kernel/drm/gem/mod.rs
+++ b/rust/kernel/drm/gem/mod.rs
@@ -14,6 +14,13 @@
};
use core::{mem, ops::Deref, ptr::NonNull};
+/// A type alias for retrieving a [`Driver`]s [`DriverFile`] implementation from its
+/// [`DriverObject`] implementation.
+///
+/// [`Driver`]: drm::Driver
+/// [`DriverFile`]: drm::file::DriverFile
+pub type ObjectFile<T> = drm::File<<<T as DriverObject>::Driver as drm::Driver>::File>;
+
/// GEM object functions, which must be implemented by drivers.
pub trait DriverObject: Sync + Send + Sized {
/// Parent `Driver` for this object.
@@ -23,18 +30,12 @@ pub trait DriverObject: Sync + Send + Sized {
fn new(dev: &drm::Device<Self::Driver>, size: usize) -> impl PinInit<Self, Error>;
/// Open a new handle to an existing object, associated with a File.
- fn open(
- _obj: &Object<Self>,
- _file: &drm::File<<Self::Driver as drm::Driver>::File>,
- ) -> Result {
+ fn open(_obj: &Object<Self>, _file: &ObjectFile<Self>) -> Result {
Ok(())
}
/// Close a handle to an existing object, associated with a File.
- fn close(
- _obj: &Object<Self>,
- _file: &drm::File<<Self::Driver as drm::Driver>::File>,
- ) {
+ fn close(_obj: &Object<Self>, _file: &ObjectFile<Self>) {
}
}
@@ -79,9 +80,8 @@ extern "C" fn open_callback<T: DriverObject>(
raw_file: *mut bindings::drm_file,
) -> core::ffi::c_int {
// SAFETY: `open_callback` is only ever called with a valid pointer to a `struct drm_file`.
- let file = unsafe {
- drm::File::<<T::Driver as drm::Driver>::File>::as_ref(raw_file)
- };
+ let file = unsafe { ObjectFile::<T>::as_ref(raw_file) };
+
// SAFETY: `open_callback` is specified in the AllocOps structure for `Object<T>`, ensuring that
// `raw_obj` is indeed contained within a `Object<T>`.
let obj = unsafe { Object::<T>::as_ref(raw_obj) };
@@ -97,7 +97,7 @@ extern "C" fn close_callback<T: DriverObject>(
raw_file: *mut bindings::drm_file,
) {
// SAFETY: `open_callback` is only ever called with a valid pointer to a `struct drm_file`.
- let file = unsafe { drm::File::<<T::Driver as drm::Driver>::File>::as_ref(raw_file) };
+ let file = unsafe { ObjectFile::<T>::as_ref(raw_file) };
// SAFETY: `close_callback` is specified in the AllocOps structure for `Object<T>`, ensuring
// that `raw_obj` is indeed contained within a `Object<T>`.
@@ -128,10 +128,7 @@ fn size(&self) -> usize {
/// Creates a new handle for the object associated with a given `File`
/// (or returns an existing one).
- fn create_handle(
- &self,
- file: &drm::File<<Self::Driver as drm::Driver>::File>,
- ) -> Result<u32>
+ fn create_handle(&self, file: &ObjectFile<Self>) -> Result<u32>
where
Self: DriverObject
{
@@ -144,10 +141,7 @@ fn create_handle(
}
/// Looks up an object by its handle for a given `File`.
- fn lookup_handle(
- file: &drm::File<<Self::Driver as drm::Driver>::File>,
- handle: u32,
- ) -> Result<ARef<Self>>
+ fn lookup_handle(file: &ObjectFile<Self>, handle: u32) -> Result<ARef<Self>>
where
Self: DriverObject
{
--
2.49.0
More information about the dri-devel
mailing list