Re: [PATCH 5/5] rust: serdev: Pause receive callback before calling unbind
From: Markus Probst
Date: Sun Sep 06 2026 - 13:38:56 EST
On Sun, 2026-09-06 at 18:20 +0200, Danilo Krummrich wrote:
> On Sun Sep 6, 2026 at 5:55 PM CEST, Markus Probst wrote:
> > @@ -200,10 +203,14 @@ extern "C" fn receive_buf_callback(
> > // INVARIANT: `sdev` is valid for the duration of `receive_buf_callback()`.
> > let sdev = unsafe { &*sdev.cast::<Device<device::BoundInternal>>() };
> >
> > - // SAFETY: `receive_buf_callback` is only ever called after a successful call to
> > - // `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called
> > - // and stored a `Pin<KBox<PrivateData<'_, T>>>`.
> > - let private_data = unsafe { sdev.as_ref().drvdata_borrow::<PrivateData<'_, T>>() };
> > + // SAFETY:
> > + // - `receive_buf_callback` is only ever called after a successful call to `probe_callback`,
> > + // hence it's guaranteed that `Device::set_drvdata()` has been called and stored a
> > + // `Pin<KBox<PrivateData<'_, T>>>`.
> > + // - `unbind_callback` calls `serdev_device_pause_rx` before accessing the driver data,
> > + // which guarantees that this function will not overlap with it. Thus we have exclusive
> > + // access.
> > + let private_data = unsafe { sdev.as_ref().drvdata_borrow_mut::<PrivateData<'_, T>>() };
>
> This would break the driver core's lifetime design. Any kind of registration
> (such as class device, auxiliary, IRQ, etc.) may borrow fields from the bus
> device private data. The whole design is based on the guarantee that we never
> construct a mutable reference of the bus device private data.
Thanks for the info.
That explains why unbind doesn't provide a mutable reference on
platform drivers either.
I will drop the 2 patches in the next revision.
Thanks
- Markus Probst
Attachment:
signature.asc
Description: This is a digitally signed message part