Skip to content

Commit 6ee48ae

Browse files
LyudeDanilo Krummrich
authored andcommitted
rust: drm: gem: Use NonNull for Object::dev
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 <[email protected]> Reviewed-by: Daniel Almeida <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 61479ae commit 6ee48ae

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

rust/kernel/drm/gem/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<T> BaseObject for T where Self: crate::types::AlwaysRefCounted + IntoGEMObj
177177
#[pin_data]
178178
pub struct Object<T: DriverObject + Send + Sync> {
179179
obj: Opaque<bindings::drm_gem_object>,
180-
dev: *const drm::Device<T::Driver>,
180+
dev: NonNull<drm::Device<T::Driver>>,
181181
#[pin]
182182
data: T,
183183
}
@@ -212,7 +212,7 @@ impl<T: DriverObject> Object<T> {
212212
data <- T::new(dev, size),
213213
// INVARIANT: The drm subsystem guarantees that the `struct drm_device` will live
214214
// as long as the GEM object lives.
215-
dev,
215+
dev: dev.into(),
216216
}),
217217
GFP_KERNEL,
218218
)?;
@@ -237,7 +237,7 @@ impl<T: DriverObject> Object<T> {
237237
pub fn dev(&self) -> &drm::Device<T::Driver> {
238238
// SAFETY: The DRM subsystem guarantees that the `struct drm_device` will live as long as
239239
// the GEM object lives, hence the pointer must be valid.
240-
unsafe { &*self.dev }
240+
unsafe { self.dev.as_ref() }
241241
}
242242

243243
fn as_raw(&self) -> *mut bindings::drm_gem_object {

0 commit comments

Comments
 (0)