rust: drm: Return impl PinInit from drm::Registration::new()
Subsystems (6)
Danilo Krummrich
maintainerPATCH 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
@@ -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
Danilo Krummrich
maintainerPATCH 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
@@ -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
@@ -183,7 +183,6 @@ fn probe<'bound>( iomem, gpu_info, }), - 0, )}, _: { dev_dbg!(pdev, "Tyr initialized correctly.") }, }))
rust/kernel/drm/driver.rs +1 -2
@@ -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
Quoted 9 lines · Danilo Krummrich
Convert
drm::Registrationto 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!().
Signed-off-by Danilo Krummrich <[email protected]>
For both:
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: d511064b2e73The 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.