Re: [PATCH v4 2/3] rust: miscdevice: add additional data to MiscDeviceRegistration
From: Alice Ryhl
Date: Wed Jun 04 2025 - 05:41:33 EST
On Mon, Jun 02, 2025 at 11:16:33PM +0200, Christian Schrefl wrote:
> On 31.05.25 2:23 PM, Benno Lossin wrote:
> > On Fri May 30, 2025 at 10:46 PM CEST, Christian Schrefl wrote:
> >> + unsafe { core::ptr::drop_in_place(self.data.get()) };
> >> }
> >> }
> >>
> >> @@ -109,6 +135,13 @@ pub trait MiscDevice: Sized {
> >> /// What kind of pointer should `Self` be wrapped in.
> >> type Ptr: ForeignOwnable + Send + Sync;
> >>
> >> + /// The additional data carried by the [`MiscDeviceRegistration`] for this [`MiscDevice`].
> >> + /// If no additional data is required than the unit type `()` should be used.
> >> + ///
> >> + /// This data can be accessed in [`MiscDevice::open()`] using
> >> + /// [`MiscDeviceRegistration::data()`].
> >> + type RegistrationData: Sync;
> >
> > Why do we require `Sync` here?
>
> Needed for `MiscDeviceRegistration` to be `Send`, see response above.
Even if `MiscDeviceRegistration` is non-Send, the registration data must
still be Sync. The f_ops->open callback can *always* be called from any
thread no matter what we do here, so the data it gives you access must
always be Sync no matter what.
Alice