From: Danilo Krummrich <dakr@kernel.org>
To: dakr@kernel.org, aliceryhl@google.com, acourbot@nvidia.com,
daniel.almeida@collabora.com, ojeda@kernel.org, boqun@kernel.org,
gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, tmgross@umich.edu, tamird@kernel.org,
work@onurozkan.dev, brauner@kernel.org, lyude@redhat.com,
j@jananu.net, alvin.sun@linux.dev, deborah.brouwer@collabora.com,
laura.nao@collabora.com, beata.michalska@arm.com
Cc: nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 6/7] rust: drm: return impl PinInit from DriverFile::open()
Date: Sat, 7 Nov 2026 03:03:24 +0100 [thread overview]
Message-ID: <20261107021427.2105374-7-dakr@kernel.org> (raw)
In-Reply-To: <20261107021427.2105374-1-dakr@kernel.org>
Change DriverFile::open() to return impl PinInit<Self, Error> instead of
Result<Pin<KBox<Self>>>, consistent with how bus device private data
works.
Drivers no longer need to allocate a Pin<KBox<_>> themselves; they just
return an initializer and the subsystem takes care of the allocation.
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
drivers/gpu/drm/nova/file.rs | 5 ++---
drivers/gpu/drm/tyr/file.rs | 4 ++--
rust/kernel/drm/file.rs | 5 +++--
rust/kernel/drm/gem/shmem.rs | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/nova/file.rs b/drivers/gpu/drm/nova/file.rs
index a05264917a0b..13642f83289d 100644
--- a/drivers/gpu/drm/nova/file.rs
+++ b/drivers/gpu/drm/nova/file.rs
@@ -7,7 +7,6 @@
};
use crate::gem::NovaObject;
use kernel::{
- alloc::flags::*,
drm::{
self,
gem::BaseObject,
@@ -103,8 +102,8 @@ fn write_info<T: AsBytes>(info: &mut uapi::drm_nova_info, value: T) -> Result {
impl drm::file::DriverFile for File {
type Driver = NovaDriver;
- fn open(_dev: &NovaDevice) -> Result<Pin<KBox<Self>>> {
- Ok(KBox::new(Self, GFP_KERNEL)?.into())
+ fn open(_dev: &NovaDevice) -> impl PinInit<Self, Error> {
+ Ok(Self)
}
}
diff --git a/drivers/gpu/drm/tyr/file.rs b/drivers/gpu/drm/tyr/file.rs
index 9f60a90d4948..6850708cfcdd 100644
--- a/drivers/gpu/drm/tyr/file.rs
+++ b/drivers/gpu/drm/tyr/file.rs
@@ -25,8 +25,8 @@ pub(crate) struct TyrDrmFileData {}
impl drm::file::DriverFile for TyrDrmFileData {
type Driver = TyrDrmDriver;
- fn open(_dev: &drm::Device<Self::Driver>) -> Result<Pin<KBox<Self>>> {
- KBox::try_pin_init(try_pin_init!(Self {}), GFP_KERNEL)
+ fn open(_dev: &drm::Device<Self::Driver>) -> impl PinInit<Self, Error> {
+ Ok(Self {})
}
}
diff --git a/rust/kernel/drm/file.rs b/rust/kernel/drm/file.rs
index 10160601ce5a..bd5e4ca2977f 100644
--- a/rust/kernel/drm/file.rs
+++ b/rust/kernel/drm/file.rs
@@ -18,7 +18,7 @@ pub trait DriverFile {
type Driver: drm::Driver;
/// Open a new file (called when a client opens the DRM device).
- fn open(device: &drm::Device<Self::Driver>) -> Result<Pin<KBox<Self>>>;
+ fn open(device: &drm::Device<Self::Driver>) -> impl PinInit<Self, Error>;
}
/// An open DRM File.
@@ -70,7 +70,8 @@ pub(crate) extern "C" fn open_callback(
// SAFETY: `raw_file` is a valid pointer to a `struct drm_file`.
let file = unsafe { File::<T>::from_raw(raw_file) };
- let inner = match T::open(drm) {
+ let init = T::open(drm);
+ let inner = match KBox::try_pin_init(init, GFP_KERNEL) {
Err(e) => {
return e.to_errno();
}
diff --git a/rust/kernel/drm/gem/shmem.rs b/rust/kernel/drm/gem/shmem.rs
index 24cb5343e0db..1a4f81e3b5b5 100644
--- a/rust/kernel/drm/gem/shmem.rs
+++ b/rust/kernel/drm/gem/shmem.rs
@@ -604,8 +604,8 @@ struct KunitObject {}
impl drm::file::DriverFile for KunitFile {
type Driver = KunitDriver;
- fn open(_dev: &drm::Device<KunitDriver>) -> Result<Pin<KBox<Self>>> {
- Ok(KBox::new(Self, GFP_KERNEL)?.into())
+ fn open(_dev: &drm::Device<KunitDriver>) -> impl PinInit<Self, Error> {
+ Ok(Self)
}
}
--
2.56.0
next prev parent reply other threads:[~2026-11-07 2:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 2:03 [PATCH v2 0/7] lifetime-parameterized DRM File private data Danilo Krummrich
2026-11-07 2:03 ` [PATCH v2 1/7] rust: drm: rename Ioctl device context to Userspace Danilo Krummrich
2026-11-11 9:21 ` Gary Guo
2026-11-07 2:03 ` [PATCH v2 2/7] rust: drm: gem: gate open/close callbacks with RegistrationGuard Danilo Krummrich
2026-11-11 9:21 ` Gary Guo
2026-11-07 2:03 ` [PATCH v2 3/7] rust: drm: move file_operations from gem to device Danilo Krummrich
2026-11-11 9:22 ` Gary Guo
2026-11-07 2:03 ` [PATCH v2 4/7] rust: fs: add iminor() helper Danilo Krummrich
2026-11-11 9:22 ` Gary Guo
2026-11-07 2:03 ` [PATCH v2 5/7] rust: drm: wrap fops open with RegistrationGuard Danilo Krummrich
2026-11-11 9:25 ` Gary Guo
2026-11-07 2:03 ` Danilo Krummrich [this message]
2026-11-11 9:52 ` [PATCH v2 6/7] rust: drm: return impl PinInit from DriverFile::open() Gary Guo
2026-11-11 17:29 ` Daniel Almeida
2026-11-07 2:03 ` [PATCH v2 7/7] rust: drm: make Driver::File lifetime-parameterized Danilo Krummrich
2026-11-07 2:34 ` sashiko-bot
2026-11-07 8:16 ` Alice Ryhl
2026-11-07 13:26 ` Danilo Krummrich
2026-11-10 20:43 ` Alice Ryhl
2026-11-11 11:08 ` Gary Guo
2026-11-11 17:30 ` Daniel Almeida
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=20261107021427.2105374-7-dakr@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=alvin.sun@linux.dev \
--cc=beata.michalska@arm.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=deborah.brouwer@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=j@jananu.net \
--cc=laura.nao@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.