* [PATCH v2] rust: drm/gem: Remove Object.dev
@ 2025-10-21 17:21 Lyude Paul
2025-10-21 17:28 ` Alice Ryhl
0 siblings, 1 reply; 2+ messages in thread
From: Lyude Paul @ 2025-10-21 17:21 UTC (permalink / raw)
To: dri-devel, rust-for-linux, Alice Ryhl
Cc: Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda,
Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Daniel Almeida,
Shankari Anand, Asahi Lina, open list
I noticed by chance that there's actually already a pointer to this in
struct drm_gem_object. So, no use in carrying this around!
Signed-off-by: Lyude Paul <lyude@redhat.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
---
V2:
* Improve safety comment in Object.dev()
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 30c853988b942..d984148403679 100644
--- a/rust/kernel/drm/gem/mod.rs
+++ b/rust/kernel/drm/gem/mod.rs
@@ -187,12 +187,10 @@ impl<T: IntoGEMObject> BaseObject for T {}
/// Invariants
///
/// - `self.obj` is a valid instance of a `struct drm_gem_object`.
-/// - `self.dev` is always a valid pointer to a `struct drm_device`.
#[repr(C)]
#[pin_data]
pub struct Object<T: DriverObject + Send + Sync> {
obj: Opaque<bindings::drm_gem_object>,
- dev: NonNull<drm::Device<T::Driver>>,
#[pin]
data: T,
}
@@ -222,9 +220,6 @@ pub fn new(dev: &drm::Device<T::Driver>, size: usize) -> Result<ARef<Self>> {
try_pin_init!(Self {
obj: Opaque::new(bindings::drm_gem_object::default()),
data <- T::new(dev, size),
- // INVARIANT: The drm subsystem guarantees that the `struct drm_device` will live
- // as long as the GEM object lives.
- dev: dev.into(),
}),
GFP_KERNEL,
)?;
@@ -247,9 +242,13 @@ pub fn new(dev: &drm::Device<T::Driver>, size: usize) -> Result<ARef<Self>> {
/// Returns the `Device` that owns this GEM object.
pub fn dev(&self) -> &drm::Device<T::Driver> {
- // SAFETY: The DRM subsystem guarantees that the `struct drm_device` will live as long as
- // the GEM object lives, hence the pointer must be valid.
- unsafe { self.dev.as_ref() }
+ // SAFETY:
+ // - `struct drm_gem_object.dev` is initialized and valid for as long as the GEM
+ // object lives.
+ // - The device we used for creating the gem object is passed as &drm::Device<T::Driver> to
+ // Object::<T>::new(), so we know that `T::Driver` is the right generic parameter to use
+ // here.
+ unsafe { drm::Device::from_raw((*self.as_raw()).dev) }
}
fn as_raw(&self) -> *mut bindings::drm_gem_object {
base-commit: 77ed4376d7c5de8be1f2612d6b4777077fb5fdb2
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] rust: drm/gem: Remove Object.dev
2025-10-21 17:21 [PATCH v2] rust: drm/gem: Remove Object.dev Lyude Paul
@ 2025-10-21 17:28 ` Alice Ryhl
0 siblings, 0 replies; 2+ messages in thread
From: Alice Ryhl @ 2025-10-21 17:28 UTC (permalink / raw)
To: Lyude Paul
Cc: dri-devel, rust-for-linux, Danilo Krummrich, David Airlie,
Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Daniel Almeida, Shankari Anand, Asahi Lina,
open list
On Tue, Oct 21, 2025 at 7:22 PM Lyude Paul <lyude@redhat.com> wrote:
>
> I noticed by chance that there's actually already a pointer to this in
> struct drm_gem_object. So, no use in carrying this around!
>
> Signed-off-by: Lyude Paul <lyude@redhat.com>
> Acked-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-21 17:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21 17:21 [PATCH v2] rust: drm/gem: Remove Object.dev Lyude Paul
2025-10-21 17:28 ` Alice Ryhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).