rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Lyude Paul <lyude@redhat.com>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	"Danilo Krummrich" <dakr@kernel.org>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Asahi Lina" <lina+kernel@asahilina.net>,
	"Shankari Anand" <shankari.ak0208@gmail.com>
Subject: Re: [PATCH] rust: drm/gem: Remove Object.dev
Date: Fri, 17 Oct 2025 13:10:17 +0000	[thread overview]
Message-ID: <aPJAOXtv2knFkyDP@google.com> (raw)
In-Reply-To: <20251016202044.2748678-1-lyude@redhat.com>

On Thu, Oct 16, 2025 at 04:18:58PM -0400, Lyude Paul 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>
> ---
>  rust/kernel/drm/gem/mod.rs | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
> index 30c853988b942..28d929edae267 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,9 @@ 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.
> +        unsafe { drm::Device::from_raw((*self.as_raw()).dev) }

The wording here and in the invariants could be improved to say that
T::Driver is the right choice for the generic parameter.

Alice

      parent reply	other threads:[~2025-10-17 13:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-16 20:18 [PATCH] rust: drm/gem: Remove Object.dev Lyude Paul
2025-10-16 21:17 ` Danilo Krummrich
2025-10-17 13:10 ` Alice Ryhl [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aPJAOXtv2knFkyDP@google.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=lina+kernel@asahilina.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=shankari.ak0208@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).