]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
rust: drm: gem: Use NonNull for Object::dev
authorLyude Paul <lyude@redhat.com>
Tue, 13 May 2025 22:09:54 +0000 (18:09 -0400)
committerDanilo Krummrich <dakr@kernel.org>
Tue, 13 May 2025 22:26:08 +0000 (00:26 +0200)
There is usually not much of a reason to use a raw pointer in a data
struct, so move this to NonNull instead.

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

index 0cafa4a424206d4223ebf222b96277cd5a628f50..df8f9fdae5c22a502846252b497f91fd3e5f4a8b 100644 (file)
@@ -177,7 +177,7 @@ impl<T> BaseObject for T where Self: crate::types::AlwaysRefCounted + IntoGEMObj
 #[pin_data]
 pub struct Object<T: DriverObject + Send + Sync> {
     obj: Opaque<bindings::drm_gem_object>,
-    dev: *const drm::Device<T::Driver>,
+    dev: NonNull<drm::Device<T::Driver>>,
     #[pin]
     data: T,
 }
@@ -212,7 +212,7 @@ impl<T: DriverObject> Object<T> {
                 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: dev.into(),
             }),
             GFP_KERNEL,
         )?;
@@ -237,7 +237,7 @@ impl<T: DriverObject> Object<T> {
     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 }
+        unsafe { self.dev.as_ref() }
     }
 
     fn as_raw(&self) -> *mut bindings::drm_gem_object {