The #[pin_data] and #[pin] annotations are not necessary for
drm::Device, since we don't use any pin-init macros, but only
__pinned_init() on the impl PinInit<T::Data, Error> argument of
drm::Device::new().
Fixes: 1e4b8896c0f3 ("rust: drm: add device abstraction")
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
rust/kernel/drm/device.rs | 2 --
1 file changed, 2 deletions(-)
diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
index d19410deaf6c..d0a9528121f1 100644
--- a/rust/kernel/drm/device.rs
+++ b/rust/kernel/drm/device.rs
@@ -54,10 +54,8 @@ macro_rules! drm_legacy_fields {
///
/// `self.dev` is a valid instance of a `struct device`.
#[repr(C)]
-#[pin_data]
pub struct Device<T: drm::Driver> {
dev: Opaque<bindings::drm_device>,
- #[pin]
data: T::Data,
}
--
2.50.0
On Thu Jul 31, 2025 at 5:48 PM CEST, Danilo Krummrich wrote: > The #[pin_data] and #[pin] annotations are not necessary for > drm::Device, since we don't use any pin-init macros, but only > __pinned_init() on the impl PinInit<T::Data, Error> argument of > drm::Device::new(). > > Fixes: 1e4b8896c0f3 ("rust: drm: add device abstraction") > Signed-off-by: Danilo Krummrich <dakr@kernel.org> Reviewed-by: Benno Lossin <lossin@kernel.org> --- Cheers, Benno > --- > rust/kernel/drm/device.rs | 2 -- > 1 file changed, 2 deletions(-)
On Thu Jul 31, 2025 at 5:48 PM CEST, Danilo Krummrich wrote: > The #[pin_data] and #[pin] annotations are not necessary for > drm::Device, since we don't use any pin-init macros, but only > __pinned_init() on the impl PinInit<T::Data, Error> argument of > drm::Device::new(). But you're still pinning `Device`, right? > Fixes: 1e4b8896c0f3 ("rust: drm: add device abstraction") > Signed-off-by: Danilo Krummrich <dakr@kernel.org> > --- > rust/kernel/drm/device.rs | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs > index d19410deaf6c..d0a9528121f1 100644 > --- a/rust/kernel/drm/device.rs > +++ b/rust/kernel/drm/device.rs > @@ -54,10 +54,8 @@ macro_rules! drm_legacy_fields { > /// > /// `self.dev` is a valid instance of a `struct device`. > #[repr(C)] > -#[pin_data] > pub struct Device<T: drm::Driver> { > dev: Opaque<bindings::drm_device>, > - #[pin] > data: T::Data, Looking at this code again, I also noticed that it was wrong before this patch: `Device<T>` implemented `Unpin` if `T::Data` did which is most likely wrong (or is `drm_device` not address sensitive?). So good to see that fixed, thanks! --- Cheers, Benno > } >
On Thu Jul 31, 2025 at 8:54 PM CEST, Benno Lossin wrote: > On Thu Jul 31, 2025 at 5:48 PM CEST, Danilo Krummrich wrote: >> The #[pin_data] and #[pin] annotations are not necessary for >> drm::Device, since we don't use any pin-init macros, but only >> __pinned_init() on the impl PinInit<T::Data, Error> argument of >> drm::Device::new(). > > But you're still pinning `Device`, right? A drm::Device instance never exists other than as ARef<drm::Device>. >> Fixes: 1e4b8896c0f3 ("rust: drm: add device abstraction") >> Signed-off-by: Danilo Krummrich <dakr@kernel.org> >> --- >> rust/kernel/drm/device.rs | 2 -- >> 1 file changed, 2 deletions(-) >> >> diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs >> index d19410deaf6c..d0a9528121f1 100644 >> --- a/rust/kernel/drm/device.rs >> +++ b/rust/kernel/drm/device.rs >> @@ -54,10 +54,8 @@ macro_rules! drm_legacy_fields { >> /// >> /// `self.dev` is a valid instance of a `struct device`. >> #[repr(C)] >> -#[pin_data] >> pub struct Device<T: drm::Driver> { >> dev: Opaque<bindings::drm_device>, >> - #[pin] >> data: T::Data, > > Looking at this code again, I also noticed that it was wrong before this > patch: `Device<T>` implemented `Unpin` if `T::Data` did which is most > likely wrong (or is `drm_device` not address sensitive?). It is, but as mentioned above a drm::Device only ever exists as ARef<drm::Device>. So, in drm::Device::new() we allocate the drm::Device with __drm_dev_alloc(), initialize data in-place within this allocated memory and create an ARef<drm::Device> directly from the raw pointer returned by __drm_dev_alloc(). > So good to see that fixed, thanks! > > --- > Cheers, > Benno > >> } >>
On Fri Aug 1, 2025 at 10:21 AM CEST, Danilo Krummrich wrote: > On Thu Jul 31, 2025 at 8:54 PM CEST, Benno Lossin wrote: >> On Thu Jul 31, 2025 at 5:48 PM CEST, Danilo Krummrich wrote: >>> #[repr(C)] >>> -#[pin_data] >>> pub struct Device<T: drm::Driver> { >>> dev: Opaque<bindings::drm_device>, >>> - #[pin] >>> data: T::Data, >> >> Looking at this code again, I also noticed that it was wrong before this >> patch: `Device<T>` implemented `Unpin` if `T::Data` did which is most >> likely wrong (or is `drm_device` not address sensitive?). > > It is, but as mentioned above a drm::Device only ever exists as > ARef<drm::Device>. Yeah the `Unpin` thing isn't a problem for `ARef`, but we are theoretically allowed to implement moving out of an `ARef` (given that it is unique) when the type is `Unpin`. Thanks for confirming. --- Cheers, Benno
© 2016 - 2025 Red Hat, Inc.