Skip to contentSkip to conversation

rust: drm: Return impl PinInit from drm::Registration::new()

PATCH Applied Danilo Krummrich 2 participants 4 messages Sep 29 – Oct 10

Subsystems (6)
lore
Share & tools
lore

Danilo Krummrich

author maintainer
#0 lore raw

PATCH 1/2 rust: drm: Return impl PinInit from drm::Registration::new()

Convert drm::Registration to return an impl PinInit<Self, Error> rather than creating a separate allocation. This removes an otherwise unnecessary allocation.

Update both in-tree callers (nova, tyr) to construct their bus device private data using try_pin_init!().

---
 drivers/gpu/drm/nova/driver.rs |  27 ++++---
 drivers/gpu/drm/tyr/driver.rs  | 138 +++++++++++++++++----------------
 rust/kernel/drm/driver.rs      |  76 ++++++++++--------
 3 files changed, 130 insertions(+), 111 deletions(-)
drivers/gpu/drm/nova/driver.rs +15 -12
index 46e13fe795eb..50537efe8d94 100644
@@ -25,10 +25,11 @@
 
 pub(crate) struct NovaDriver;
 
+#[pin_data]
 pub(crate) struct Nova<'bound> {
-    #[expect(unused)]
     drm: ARef<drm::Device<NovaDriver>>,
-    _reg: drm::Registration<'bound, NovaDriver>,
+    #[pin]
+    reg: drm::Registration<'bound, NovaDriver>,
 }
 
 /// DRM registration data, accessible from ioctl handlers via the registration guard.
@@ -68,17 +69,19 @@ fn probe<'bound>(
         adev: &'bound auxiliary::Device<Core<'_>>,
         _info: &'bound Self::IdInfo,
     ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
-        let drm = drm::UnregisteredDevice::<Self>::new(adev, Ok(()))?;
-        let reg_data = DrmRegData {
-            api: NovaCoreApi::of(adev)?,
-        };
-        // SAFETY: `reg` is stored in `Nova` and dropped when the driver is unbound; it is
-        // never forgotten.
-        let reg = unsafe { drm::Registration::new(adev.as_ref(), drm, reg_data, 0)? };
-
-        Ok(Nova {
+        try_pin_init!(Self::Data {
+            reg <- {
+                let drm = drm::UnregisteredDevice::<Self>::new(adev, Ok(()))?;
+
+                let reg_data = DrmRegData {
+                    api: NovaCoreApi::of(adev)?,
+                };
+
+                // SAFETY: `reg` is stored in `Self::Data` and dropped when the driver is unbound;
+                // it is never forgotten.
+                unsafe { drm::Registration::new(adev.as_ref(), drm, reg_data, 0) }
+            },
             drm: reg.device().into(),
-            _reg: reg,
         })
     }
 }
drivers/gpu/drm/tyr/driver.rs +71 -67

150 lines not on this page · raw message

rust/kernel/drm/driver.rs +44 -32

107 lines not on this page · raw message

base-commit: 10a6623a24a85708650efad7be15182289403cd7

Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH 2/2 rust: drm: Remove unused flags argument from Registration::new()

The flags argument to drm_dev_register() is only passed to the deprecated .load() callback. Rust DRM drivers always set this callback to NULL, so the argument has no effect.

Remove the argument from drm::Registration::new(), pass zero to drm_dev_register(), and update the Nova and Tyr callers.

---
 drivers/gpu/drm/nova/driver.rs | 2 +-
 drivers/gpu/drm/tyr/driver.rs  | 1 -
 rust/kernel/drm/driver.rs      | 3 +--
 3 files changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/nova/driver.rs +1 -1
index 50537efe8d94..5fe98f646082 100644
@@ -79,7 +79,7 @@ fn probe<'bound>(
 
                 // SAFETY: `reg` is stored in `Self::Data` and dropped when the driver is unbound;
                 // it is never forgotten.
-                unsafe { drm::Registration::new(adev.as_ref(), drm, reg_data, 0) }
+                unsafe { drm::Registration::new(adev.as_ref(), drm, reg_data) }
             },
             drm: reg.device().into(),
         })
drivers/gpu/drm/tyr/driver.rs +0 -1
index 6e1008290b5f..c2b99d67369f 100644
@@ -183,7 +183,6 @@ fn probe<'bound>(
                         iomem,
                         gpu_info,
                     }),
-                    0,
                 )},
                 _: { dev_dbg!(pdev, "Tyr initialized correctly.") },
             }))
rust/kernel/drm/driver.rs +1 -2
index 13aa609350b1..f6db91e81e79 100644
@@ -169,7 +169,6 @@ pub unsafe fn new<E>(
         dev: &'a device::Device<device::Bound>,
         drm: drm::UnregisteredDevice<T>,
         data: impl PinInit<T::RegistrationData<'a>, E>,
-        flags: usize,
     ) -> impl PinInit<Self, Error>
     where
         Error: From<E>,
@@ -196,7 +195,7 @@ pub unsafe fn new<E>(
                 unsafe { *drm.registration_data.get() = ptr };
 
                 // SAFETY: `drm` is a valid, initialized but not yet registered DRM device.
-                let ret = unsafe { bindings::drm_dev_register(drm.as_raw(), flags) };
+                let ret = unsafe { bindings::drm_dev_register(drm.as_raw(), 0) };
                 to_result(ret).inspect_err(|_| {
                     // SAFETY: `drm_dev_register()` synchronizes SRCU on failure, so no
                     // concurrent access to `registration_data` is possible at this point.
Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/2
#2 lore raw
In reply to Danilo Krummrich
Quoted 9 lines · Danilo Krummrich

Convert drm::Registration to return an impl PinInit<Self, Error> rather than creating a separate allocation. This removes an otherwise unnecessary allocation.

Update both in-tree callers (nova, tyr) to construct their bus device private data using try_pin_init!().

For both:

author maintainer Applied
#3 lore raw
In reply to Danilo Krummrich
Quoted 1 line · Danilo Krummrich

[PATCH 1/2] rust: drm: Return impl PinInit from drm::Registration::new()

Applied, thanks!

Branch: drm-rust-next
Tree: https://gitlab.freedesktop.org/drm/rust/kernel.git

[1/2] rust: drm: Return impl PinInit from drm::Registration::new()

      commit: 700eed1364e8
[2/2] rust: drm: Remove unused flags argument from Registration::new()
      commit: d511064b2e73

The patches will appear in the next linux-next integration (typically within 24 hours on weekdays).

The patches are queued up for the upcoming merge window for the next major kernel release.