Commit b36ff40b authored by Lyude Paul's avatar Lyude Paul Committed by Danilo Krummrich
Browse files

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: default avatarLyude Paul <lyude@redhat.com>
Reviewed-by: default avatarDaniel Almeida <daniel.almeida@collabora.com>
Link: https://lore.kernel.org/r/20250513221046.903358-4-lyude@redhat.com


[ Fixup s/into_gem_obj()/as_raw()/ in safety comment. - Danilo ]
Signed-off-by: default avatarDanilo Krummrich <dakr@kernel.org>
parent 36b1ccbf
Loading
Loading
Loading
Loading
+9 −19
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
    prelude::*,
    types::{ARef, Opaque},
};
use core::{mem, ops::Deref, ptr, ptr::NonNull};
use core::{mem, ops::Deref, ptr::NonNull};

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

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

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

    fn into_gem_obj(&self) -> &Opaque<bindings::drm_gem_object> {
        &self.obj
    fn as_raw(&self) -> *mut bindings::drm_gem_object {
        self.obj.get()
    }

    unsafe fn as_ref<'a>(self_ptr: *mut bindings::drm_gem_object) -> &'a Self {
@@ -119,9 +118,8 @@ pub trait BaseObject
{
    /// Returns the size of the object in bytes.
    fn size(&self) -> usize {
        // SAFETY: `self.into_gem_obj()` is guaranteed to be a pointer to a valid `struct
        // drm_gem_object`.
        unsafe { (*self.into_gem_obj().get()).size }
        // SAFETY: `self.as_raw()` is guaranteed to be a pointer to a valid `struct drm_gem_object`.
        unsafe { (*self.as_raw()).size }
    }

    /// Creates a new handle for the object associated with a given `File`
@@ -133,11 +131,7 @@ fn create_handle(
        let mut handle: u32 = 0;
        // SAFETY: The arguments are all valid per the type invariants.
        to_result(unsafe {
            bindings::drm_gem_handle_create(
                file.as_raw().cast(),
                self.into_gem_obj().get(),
                &mut handle,
            )
            bindings::drm_gem_handle_create(file.as_raw().cast(), self.as_raw(), &mut handle)
        })?;
        Ok(handle)
    }
@@ -171,14 +165,10 @@ fn lookup_handle(
    /// Creates an mmap offset to map the object from userspace.
    fn create_mmap_offset(&self) -> Result<u64> {
        // SAFETY: The arguments are valid per the type invariant.
        to_result(unsafe { bindings::drm_gem_create_mmap_offset(self.into_gem_obj().get()) })?;
        to_result(unsafe { bindings::drm_gem_create_mmap_offset(self.as_raw()) })?;

        // SAFETY: The arguments are valid per the type invariant.
        Ok(unsafe {
            bindings::drm_vma_node_offset_addr(ptr::addr_of_mut!(
                (*self.into_gem_obj().get()).vma_node
            ))
        })
        Ok(unsafe { bindings::drm_vma_node_offset_addr(&raw mut (*self.as_raw()).vma_node) })
    }
}