Now that we've cleaned up the generics for gem objects a bit, we're still left with a bit of generic soup around referring to the Object implementation for a given driver. Let's clean this up a bit by re-using the DriverObject identifier we just freed up and turning it into a type alias for referring to a driver's gem object implementation.
Signed-off-by: Lyude Paul <ly...@redhat.com> --- rust/kernel/drm/gem/mod.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index f0455cc2aff2d..c17b36948bae3 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -14,6 +14,9 @@ }; use core::{mem, ops::Deref, ptr::NonNull}; +/// A type alias for the Object type in use by a [`drm::Driver`]. +pub type DriverObject<T> = <<T as BaseDriverObject>::Driver as drm::Driver>::Object; + /// GEM object functions, which must be implemented by drivers. pub trait BaseDriverObject: Sync + Send + Sized { /// Parent `Driver` for this object. @@ -24,18 +27,14 @@ pub trait BaseDriverObject: Sync + Send + Sized { /// Open a new handle to an existing object, associated with a File. fn open( - _obj: &<Self::Driver as drm::Driver>::Object, + _obj: &DriverObject<Self>, _file: &drm::File<<Self::Driver as drm::Driver>::File>, ) -> Result { Ok(()) } /// Close a handle to an existing object, associated with a File. - fn close( - _obj: &<Self::Driver as drm::Driver>::Object, - _file: &drm::File<<Self::Driver as drm::Driver>::File>, - ) { - } + fn close(_obj: &DriverObject<Self>, _file: &drm::File<<Self::Driver as drm::Driver>::File>) {} } /// Trait that represents a GEM object subtype @@ -82,7 +81,7 @@ extern "C" fn open_callback<T: BaseDriverObject>( let file = unsafe { drm::File::<<T::Driver as drm::Driver>::File>::as_ref(raw_file) }; // SAFETY: `open_callback` is specified in the AllocOps structure for `DriverObject<T>`, // ensuring that `raw_obj` is contained within a `DriverObject<T>` - let obj = unsafe { <<T::Driver as drm::Driver>::Object as IntoGEMObject>::as_ref(raw_obj) }; + let obj = unsafe { DriverObject::<T>::as_ref(raw_obj) }; match T::open(obj, file) { Err(e) => e.to_errno(), @@ -99,7 +98,7 @@ extern "C" fn close_callback<T: BaseDriverObject>( // SAFETY: `close_callback` is specified in the AllocOps structure for `Object<T>`, ensuring // that `raw_obj` is indeed contained within a `Object<T>`. - let obj = unsafe { <<T::Driver as drm::Driver>::Object as IntoGEMObject>::as_ref(raw_obj) }; + let obj = unsafe { DriverObject::<T>::as_ref(raw_obj) }; T::close(obj, file); } -- 2.49.0