[PATCH 1/4] rust: drm: gem: Use NonNull for Object::dev
Daniel Almeida
daniel.almeida at collabora.com
Fri May 9 20:59:15 UTC 2025
Hi Lyude,
> On 1 May 2025, at 15:33, Lyude Paul <lyude at redhat.com> wrote:
>
> 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 at redhat.com>
> ---
> rust/kernel/drm/gem/mod.rs | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
> index 0cafa4a424206..df8f9fdae5c22 100644
> --- a/rust/kernel/drm/gem/mod.rs
> +++ b/rust/kernel/drm/gem/mod.rs
> @@ -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 @@ pub fn new(dev: &drm::Device<T::Driver>, size: usize) -> Result<ARef<Self>> {
> 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 @@ pub fn new(dev: &drm::Device<T::Driver>, size: usize) -> Result<ARef<Self>> {
> 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 {
> --
> 2.48.1
>
>
Reviewed-by: Daniel Almeida <daniel.almeida at collabora.com>
More information about the dri-devel
mailing list