]> www.infradead.org Git - users/jedix/linux-maple.git/commit
rust: drm: gem: Refactor IntoGEMObject::from_gem_obj() to as_ref()
authorLyude Paul <lyude@redhat.com>
Tue, 13 May 2025 22:09:55 +0000 (18:09 -0400)
committerDanilo Krummrich <dakr@kernel.org>
Tue, 13 May 2025 22:26:16 +0000 (00:26 +0200)
commit36b1ccbfa0c2f45fae3e07bf66e40d7fd6704874
treeb489cf0e27a46cfff5209e6245d2c893a57ce426
parent6ee48aee8c705717051109ff889f2a1d4f409ea9
rust: drm: gem: Refactor IntoGEMObject::from_gem_obj() to as_ref()

There's a few issues with this function, mainly:

* This function -probably- should have been unsafe from the start. Pointers
  are not always necessarily valid, but you want a function that does
  field-projection for a pointer that can travel outside of the original
  struct to be unsafe, at least if I understand properly.
* *mut Self is not terribly useful in this context, the majority of uses of
  from_gem_obj() grab a *mut Self and then immediately convert it into a
  &'a Self. It also goes against the ffi conventions we've set in the rest
  of the kernel thus far.
* from_gem_obj() also doesn't follow the naming conventions in the rest of
  the DRM bindings at the moment, as_ref() would be a better name.

So, let's:

* Make from_gem_obj() unsafe
* Convert it to return &'a Self
* Rename it to as_ref()
* Update all call locations

Signed-off-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://lore.kernel.org/r/20250513221046.903358-3-lyude@redhat.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/drm/gem/mod.rs