From: Markus Probst <markus.probst@posteo.de>
To: Danilo Krummrich <dakr@kernel.org>,
gregkh@linuxfoundation.org, rafael@kernel.org, johan@kernel.org,
david.m.ertman@intel.com, iweiny@kernel.org, leon@kernel.org,
ojeda@kernel.org, boqun@kernel.org, gary@garyguo.net,
bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
daniel.almeida@collabora.com, tamird@kernel.org,
acourbot@nvidia.com, work@onurozkan.dev, igor.korotin@linux.dev,
bhelgaas@google.com, kwilczynski@kernel.org
Cc: driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
linux-serial@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH 4/7] rust: serdev: remove the unbind() callback
Date: Fri, 13 Nov 2026 21:14:25 +0000 [thread overview]
Message-ID: <3e4aafb4c2dab636e9f113199d4cb95e0af9c6bb.camel@posteo.de> (raw)
In-Reply-To: <20261112005455.1224352-5-dakr@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 4332 bytes --]
On Thu, 2026-11-12 at 01:52 +0100, Danilo Krummrich wrote:
> The driver model uses native Rust lifetimes to let driver data retain
> device resources and a Device<Bound> reference for the duration of the
> binding. Both remain accessible from the destructor, so a separate
> unbind() callback is no longer needed.
>
> Remove serdev::Driver::unbind() and the adapter's remove callback and
> document that device teardown belongs in Drop or PinnedDrop.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> ---
> rust/kernel/serdev.rs | 41 ++++-------------------------------------
> 1 file changed, 4 insertions(+), 37 deletions(-)
>
> diff --git a/rust/kernel/serdev.rs b/rust/kernel/serdev.rs
> index 17ca504b7f8d..fd998b68b74f 100644
> --- a/rust/kernel/serdev.rs
> +++ b/rust/kernel/serdev.rs
> @@ -81,7 +81,6 @@ unsafe fn register(
> unsafe {
> (*sdrv.get()).driver.name = name.as_char_ptr();
> (*sdrv.get()).probe = Some(Self::probe_callback);
> - (*sdrv.get()).remove = Some(Self::remove_callback);
> (*sdrv.get()).driver.of_match_table = of_table;
> (*sdrv.get()).driver.acpi_match_table = acpi_table;
> }
> @@ -210,29 +209,6 @@ extern "C" fn probe_callback(sdev: *mut bindings::serdev_device) -> kernel::ffi:
> })
> }
>
> - extern "C" fn remove_callback(sdev: *mut bindings::serdev_device) {
> - // SAFETY: The serial device bus only ever calls the remove callback with a valid pointer
> - // to a `struct serdev_device`.
> - //
> - // INVARIANT: `sdev` is valid for the duration of `remove_callback()`.
> - let sdev = unsafe { &*sdev.cast::<Device<device::CoreInternal<'_>>>() };
> -
> - // SAFETY: `remove_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: No one has exclusive access to `private_data.driver`.
> - let data = unsafe { &*private_data.driver.get() };
> - // SAFETY:
> - // - `private_data.driver` is pinned.
> - // - `remove_callback` is only ever called after a successful call to `probe_callback`,
> - // hence it's guaranteed that `private_data.driver` was initialized.
> - let data_pinned = unsafe { Pin::new_unchecked(data.assume_init_ref()) };
> -
> - T::unbind(sdev, data_pinned);
> - }
> -
> extern "C" fn receive_buf_callback(
> sdev: *mut bindings::serdev_device,
> buf: *const u8,
> @@ -365,6 +341,10 @@ pub trait Driver {
> type IdInfo: 'static;
>
> /// The type of the driver's bus device private data.
> + ///
> + /// Device teardown should be performed in [`Drop`] or [`PinnedDrop`](pin_init::PinnedDrop)
> + /// for this type. The `'bound` lifetime allows the data to retain device resources and a
> + /// [`Device<device::Bound>`] reference for use during teardown.
> type Data<'bound>: Send + Sync + 'bound;
>
> /// The table of OF device ids supported by the driver.
> @@ -382,19 +362,6 @@ fn probe<'bound>(
> id_info: Option<&'bound Self::IdInfo>,
> ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound;
>
> - /// Serial device bus device driver unbind.
> - ///
> - /// Called when a [`Device`] is unbound from its bound [`Driver`]. Implementing this callback
> - /// is optional.
> - ///
> - /// This callback serves as a place for drivers to perform teardown operations that require a
> - /// `&Device<Core>` or `&Device<Bound>` reference. For instance.
> - ///
> - /// Otherwise, release operations for driver resources should be performed in `Drop`.
> - fn unbind<'bound>(sdev: &'bound Device<device::Core<'_>>, this: Pin<&Self::Data<'bound>>) {
> - let _ = (sdev, this);
> - }
> -
> /// Serial device bus device data receive callback.
> ///
> /// Called when data got received from device.
Reviewed-by: Markus Probst <markus.probst@posteo.de>
Thanks
- Markus Probst
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 870 bytes --]
next prev parent reply other threads:[~2026-11-13 21:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 0:52 [PATCH 0/7] rust: treewide: remove driver unbind callbacks Danilo Krummrich
2026-11-12 0:52 ` [PATCH 1/7] rust: pci: remove the unbind() callback Danilo Krummrich
2026-11-12 0:52 ` [PATCH 2/7] rust: platform: " Danilo Krummrich
2026-11-12 0:52 ` [PATCH 3/7] rust: auxiliary: " Danilo Krummrich
2026-11-12 0:52 ` [PATCH 4/7] rust: serdev: " Danilo Krummrich
2026-11-13 21:14 ` Markus Probst [this message]
2026-11-12 0:52 ` [PATCH 5/7] rust: i2c: " Danilo Krummrich
2026-11-12 0:53 ` [PATCH 6/7] rust: usb: remove the disconnect() callback Danilo Krummrich
2026-11-12 0:53 ` [PATCH 7/7] rust: driver: document teardown through destructors Danilo Krummrich
2026-11-12 9:47 ` [PATCH 0/7] rust: treewide: remove driver unbind callbacks Gary Guo
2026-11-12 14:37 ` Danilo Krummrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3e4aafb4c2dab636e9f113199d4cb95e0af9c6bb.camel@posteo.de \
--to=markus.probst@posteo.de \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david.m.ertman@intel.com \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=igor.korotin@linux.dev \
--cc=iweiny@kernel.org \
--cc=johan@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®