Skip to content

Commit 1ed10db

Browse files
LyudeDarksonn
authored andcommitted
rust: drm: gem: Add DriverFile type alias
Just to reduce the clutter with the File<…> types in gem.rs. Signed-off-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20250908185239.135849-3-lyude@redhat.com Signed-off-by: Alice Ryhl <aliceryhl@google.com>
1 parent 6ea42e9 commit 1ed10db

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

rust/kernel/drm/gem/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ use crate::{
1414
};
1515
use core::{mem, ops::Deref, ptr::NonNull};
1616

17+
/// A type alias for retrieving a [`Driver`]s [`DriverFile`] implementation from its
18+
/// [`DriverObject`] implementation.
19+
///
20+
/// [`Driver`]: drm::Driver
21+
/// [`DriverFile`]: drm::file::DriverFile
22+
pub type DriverFile<T> = drm::File<<<T as DriverObject>::Driver as drm::Driver>::File>;
23+
1724
/// GEM object functions, which must be implemented by drivers.
1825
pub trait DriverObject: Sync + Send + Sized {
1926
/// Parent `Driver` for this object.
@@ -23,19 +30,12 @@ pub trait DriverObject: Sync + Send + Sized {
2330
fn new(dev: &drm::Device<Self::Driver>, size: usize) -> impl PinInit<Self, Error>;
2431

2532
/// Open a new handle to an existing object, associated with a File.
26-
fn open(
27-
_obj: &<Self::Driver as drm::Driver>::Object,
28-
_file: &drm::File<<Self::Driver as drm::Driver>::File>,
29-
) -> Result {
33+
fn open(_obj: &<Self::Driver as drm::Driver>::Object, _file: &DriverFile<Self>) -> Result {
3034
Ok(())
3135
}
3236

3337
/// Close a handle to an existing object, associated with a File.
34-
fn close(
35-
_obj: &<Self::Driver as drm::Driver>::Object,
36-
_file: &drm::File<<Self::Driver as drm::Driver>::File>,
37-
) {
38-
}
38+
fn close(_obj: &<Self::Driver as drm::Driver>::Object, _file: &DriverFile<Self>) {}
3939
}
4040

4141
/// Trait that represents a GEM object subtype
@@ -79,7 +79,8 @@ extern "C" fn open_callback<T: DriverObject>(
7979
raw_file: *mut bindings::drm_file,
8080
) -> core::ffi::c_int {
8181
// SAFETY: `open_callback` is only ever called with a valid pointer to a `struct drm_file`.
82-
let file = unsafe { drm::File::<<T::Driver as drm::Driver>::File>::from_raw(raw_file) };
82+
let file = unsafe { DriverFile::<T>::from_raw(raw_file) };
83+
8384
// SAFETY: `open_callback` is specified in the AllocOps structure for `DriverObject<T>`,
8485
// ensuring that `raw_obj` is contained within a `DriverObject<T>`
8586
let obj = unsafe { <<T::Driver as drm::Driver>::Object as IntoGEMObject>::from_raw(raw_obj) };
@@ -95,7 +96,7 @@ extern "C" fn close_callback<T: DriverObject>(
9596
raw_file: *mut bindings::drm_file,
9697
) {
9798
// SAFETY: `open_callback` is only ever called with a valid pointer to a `struct drm_file`.
98-
let file = unsafe { drm::File::<<T::Driver as drm::Driver>::File>::from_raw(raw_file) };
99+
let file = unsafe { DriverFile::<T>::from_raw(raw_file) };
99100

100101
// SAFETY: `close_callback` is specified in the AllocOps structure for `Object<T>`, ensuring
101102
// that `raw_obj` is indeed contained within a `Object<T>`.

0 commit comments

Comments
 (0)