Skip to content

Commit b36ff40

Browse files
LyudeDanilo Krummrich
authored andcommitted
rust: drm: gem: s/into_gem_obj()/as_raw()/
There's a few changes here: * The rename, of course (this should also let us drop the clippy annotation here) * Return *mut bindings::drm_gem_object instead of &Opaque<bindings::drm_gem_object> - the latter doesn't really have any benefit and just results in conversion from the rust type to the C type having to be more verbose than necessary. Signed-off-by: Lyude Paul <[email protected]> Reviewed-by: Daniel Almeida <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Fixup s/into_gem_obj()/as_raw()/ in safety comment. - Danilo ] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 36b1ccb commit b36ff40

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

rust/kernel/drm/gem/mod.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
prelude::*,
1313
types::{ARef, Opaque},
1414
};
15-
use core::{mem, ops::Deref, ptr, ptr::NonNull};
15+
use core::{mem, ops::Deref, ptr::NonNull};
1616

1717
/// GEM object functions, which must be implemented by drivers.
1818
pub trait BaseDriverObject<T: BaseObject>: Sync + Send + Sized {
@@ -42,8 +42,7 @@ pub trait IntoGEMObject: Sized + super::private::Sealed {
4242

4343
/// Returns a reference to the raw `drm_gem_object` structure, which must be valid as long as
4444
/// this owning object is valid.
45-
#[allow(clippy::wrong_self_convention)]
46-
fn into_gem_obj(&self) -> &Opaque<bindings::drm_gem_object>;
45+
fn as_raw(&self) -> *mut bindings::drm_gem_object;
4746

4847
/// Converts a pointer to a `struct drm_gem_object` into a reference to `Self`.
4948
///
@@ -101,8 +100,8 @@ extern "C" fn close_callback<T: BaseDriverObject<U>, U: BaseObject>(
101100
impl<T: DriverObject> IntoGEMObject for Object<T> {
102101
type Driver = T::Driver;
103102

104-
fn into_gem_obj(&self) -> &Opaque<bindings::drm_gem_object> {
105-
&self.obj
103+
fn as_raw(&self) -> *mut bindings::drm_gem_object {
104+
self.obj.get()
106105
}
107106

108107
unsafe fn as_ref<'a>(self_ptr: *mut bindings::drm_gem_object) -> &'a Self {
@@ -119,9 +118,8 @@ where
119118
{
120119
/// Returns the size of the object in bytes.
121120
fn size(&self) -> usize {
122-
// SAFETY: `self.into_gem_obj()` is guaranteed to be a pointer to a valid `struct
123-
// drm_gem_object`.
124-
unsafe { (*self.into_gem_obj().get()).size }
121+
// SAFETY: `self.as_raw()` is guaranteed to be a pointer to a valid `struct drm_gem_object`.
122+
unsafe { (*self.as_raw()).size }
125123
}
126124

127125
/// Creates a new handle for the object associated with a given `File`
@@ -133,11 +131,7 @@ where
133131
let mut handle: u32 = 0;
134132
// SAFETY: The arguments are all valid per the type invariants.
135133
to_result(unsafe {
136-
bindings::drm_gem_handle_create(
137-
file.as_raw().cast(),
138-
self.into_gem_obj().get(),
139-
&mut handle,
140-
)
134+
bindings::drm_gem_handle_create(file.as_raw().cast(), self.as_raw(), &mut handle)
141135
})?;
142136
Ok(handle)
143137
}
@@ -171,14 +165,10 @@ where
171165
/// Creates an mmap offset to map the object from userspace.
172166
fn create_mmap_offset(&self) -> Result<u64> {
173167
// SAFETY: The arguments are valid per the type invariant.
174-
to_result(unsafe { bindings::drm_gem_create_mmap_offset(self.into_gem_obj().get()) })?;
168+
to_result(unsafe { bindings::drm_gem_create_mmap_offset(self.as_raw()) })?;
175169

176170
// SAFETY: The arguments are valid per the type invariant.
177-
Ok(unsafe {
178-
bindings::drm_vma_node_offset_addr(ptr::addr_of_mut!(
179-
(*self.into_gem_obj().get()).vma_node
180-
))
181-
})
171+
Ok(unsafe { bindings::drm_vma_node_offset_addr(&raw mut (*self.as_raw()).vma_node) })
182172
}
183173
}
184174

0 commit comments

Comments
 (0)