{"id":2229217,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229217/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pwm/patch/20260427221155.2144848-14-dakr@kernel.org/","project":{"id":38,"url":"http://patchwork.ozlabs.org/api/1.1/projects/38/?format=json","name":"Linux PWM development","link_name":"linux-pwm","list_id":"linux-pwm.vger.kernel.org","list_email":"linux-pwm@vger.kernel.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260427221155.2144848-14-dakr@kernel.org>","date":"2026-04-27T22:11:11","name":"[13/24] rust: auxiliary: make Driver trait lifetime-parameterized","commit_ref":null,"pull_url":null,"state":"handled-elsewhere","archived":false,"hash":"8fffc18c4446367175601436669804af32b4b08a","submitter":{"id":89037,"url":"http://patchwork.ozlabs.org/api/1.1/people/89037/?format=json","name":"Danilo Krummrich","email":"dakr@kernel.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pwm/patch/20260427221155.2144848-14-dakr@kernel.org/mbox/","series":[{"id":501734,"url":"http://patchwork.ozlabs.org/api/1.1/series/501734/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pwm/list/?series=501734","date":"2026-04-27T22:10:58","name":"rust: device: Higher-Ranked Lifetime Types for device drivers","version":1,"mbox":"http://patchwork.ozlabs.org/series/501734/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2229217/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229217/checks/","tags":{},"headers":{"Return-Path":"\n <linux-pwm+bounces-8716-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pwm@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256\n header.s=k20201202 header.b=YnO230/X;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org;\n envelope-from=linux-pwm+bounces-8716-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=\"YnO230/X\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sin.lore.kernel.org (sin.lore.kernel.org\n [IPv6:2600:3c15:e001:75::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4Htz2kXqz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 08:15:23 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sin.lore.kernel.org (Postfix) with ESMTP id 817B3301B85E\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 27 Apr 2026 22:13:48 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id A011B3AD53F;\n\tMon, 27 Apr 2026 22:13:30 +0000 (UTC)","from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org\n [10.30.226.201])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A0413ACEFE;\n\tMon, 27 Apr 2026 22:13:30 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 4E832C2BCB5;\n\tMon, 27 Apr 2026 22:13:24 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777328010; cv=none;\n b=kDyl/CdAkSMwRAcQRtoiBdGCPNCtNyL8Sqx3ZpwDiuJ3cSm6cyPTPPP4ahHngwIxddfF02GfzNXNyyWZsCNO+fRFtymukxK/gQu3chcr1tgXqIo94TqbcZm0jjDp4zAeTFBySjA3pXmMTs8a0YVd8TCLf1zCpNIr96RO20vrp6U=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777328010; c=relaxed/simple;\n\tbh=Ax3xwk04aGwKxPdkslM0oEwfMzNKZapM3aM+lkIWrMQ=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=SZUVtYHfG9BwKxM9kqYUE7+2mQVpPGwf6oZO1vZjJHkMU2pA5+kq42q+UidFLXlzSZ6/RFSH9Uddm55axq/mV2dJ0CyhX9yPAKkbFZuyYkW+4RS1LeKVIO7Dg/Kq6ERqJBFIQlfO53KzPstHRlWpXmlA7reS3Uq1WKFB1KGmXsI=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org\n header.b=YnO230/X; arc=none smtp.client-ip=10.30.226.201","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1777328010;\n\tbh=Ax3xwk04aGwKxPdkslM0oEwfMzNKZapM3aM+lkIWrMQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=YnO230/XG6ZJElTZX0PkzIyd40DOrsF6s2I8DP2WYVvPn3+hNTYrJmCsXUIP2OhNa\n\t z8ESPWFYRBc8Nn698cRa+oeCjeSk3YoVusYQMt9rvQ9RL9yCJENMq0OFuJ1NO030tA\n\t XjW7BnEIqXwA9DLqtkuaUSr70K3fHUqVeK4tEa0Y3ROLqspJQfwlKf8ywsCHbC/PwB\n\t 2pKsVeJx891r/Zo5TmcCNnQ76+8oi0YNx+BOkKYyWGb1+BV3Ej8BcOFNAygrq4DVz1\n\t PXGW8J3oB+D2oGPQwK4miDKgfdKqUvSHOw2X+vrCuKo6XLSIxh5gTLh5TMpMw4cxjS\n\t Hn8S5l6Bq7qnQ==","From":"Danilo Krummrich <dakr@kernel.org>","To":"gregkh@linuxfoundation.org,\n\trafael@kernel.org,\n\tacourbot@nvidia.com,\n\taliceryhl@google.com,\n\tdavid.m.ertman@intel.com,\n\tira.weiny@intel.com,\n\tleon@kernel.org,\n\tviresh.kumar@linaro.org,\n\tm.wilczynski@samsung.com,\n\tukleinek@kernel.org,\n\tbhelgaas@google.com,\n\tkwilczynski@kernel.org,\n\tabdiel.janulgue@gmail.com,\n\trobin.murphy@arm.com,\n\tmarkus.probst@posteo.de,\n\tojeda@kernel.org,\n\tboqun@kernel.org,\n\tgary@garyguo.net,\n\tbjorn3_gh@protonmail.com,\n\tlossin@kernel.org,\n\ta.hindborg@kernel.org,\n\ttmgross@umich.edu","Cc":"driver-core@lists.linux.dev,\n\tlinux-kernel@vger.kernel.org,\n\tnova-gpu@lists.linux.dev,\n\tdri-devel@lists.freedesktop.org,\n\tlinux-pm@vger.kernel.org,\n\tlinux-pwm@vger.kernel.org,\n\tlinux-pci@vger.kernel.org,\n\trust-for-linux@vger.kernel.org,\n\tDanilo Krummrich <dakr@kernel.org>","Subject":"[PATCH 13/24] rust: auxiliary: make Driver trait\n lifetime-parameterized","Date":"Tue, 28 Apr 2026 00:11:11 +0200","Message-ID":"<20260427221155.2144848-14-dakr@kernel.org>","X-Mailer":"git-send-email 2.54.0","In-Reply-To":"<20260427221155.2144848-1-dakr@kernel.org>","References":"<20260427221155.2144848-1-dakr@kernel.org>","Precedence":"bulk","X-Mailing-List":"linux-pwm@vger.kernel.org","List-Id":"<linux-pwm.vger.kernel.org>","List-Subscribe":"<mailto:linux-pwm+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pwm+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"Make auxiliary::Driver take a lifetime parameter 'a that ties device\nresources to the binding scope.\n\nInternally, Adapter<T: Driver> becomes Adapter<F: ForLt> with a bound\nfor<'a> F::Of<'a>: Driver<'a>; module_auxiliary_driver! wraps the driver\ntype in ForLt!() so drivers don't have to.\n\nSigned-off-by: Danilo Krummrich <dakr@kernel.org>\n---\n drivers/gpu/drm/nova/driver.rs        |  9 ++--\n rust/kernel/auxiliary.rs              | 59 ++++++++++++++++++---------\n samples/rust/rust_driver_auxiliary.rs | 12 ++++--\n 3 files changed, 54 insertions(+), 26 deletions(-)","diff":"diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver.rs\nindex b1af0a099551..183d0e679a0b 100644\n--- a/drivers/gpu/drm/nova/driver.rs\n+++ b/drivers/gpu/drm/nova/driver.rs\n@@ -42,18 +42,21 @@ pub(crate) struct NovaData {\n kernel::auxiliary_device_table!(\n     AUX_TABLE,\n     MODULE_AUX_TABLE,\n-    <NovaDriver as auxiliary::Driver>::IdInfo,\n+    <NovaDriver as auxiliary::Driver<'_>>::IdInfo,\n     [(\n         auxiliary::DeviceId::new(NOVA_CORE_MODULE_NAME, AUXILIARY_NAME),\n         ()\n     )]\n );\n \n-impl auxiliary::Driver for NovaDriver {\n+impl<'a> auxiliary::Driver<'a> for NovaDriver {\n     type IdInfo = ();\n     const ID_TABLE: auxiliary::IdTable<Self::IdInfo> = &AUX_TABLE;\n \n-    fn probe(adev: &auxiliary::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {\n+    fn probe(\n+        adev: &'a auxiliary::Device<Core>,\n+        _info: &'a Self::IdInfo,\n+    ) -> impl PinInit<Self, Error> + 'a {\n         let data = try_pin_init!(NovaData { adev: adev.into() });\n \n         let drm = drm::Device::<Self>::new(adev.as_ref(), data)?;\ndiff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs\nindex 8a278ddb5b95..f593a21a16be 100644\n--- a/rust/kernel/auxiliary.rs\n+++ b/rust/kernel/auxiliary.rs\n@@ -38,22 +38,34 @@\n };\n \n /// An adapter for the registration of auxiliary drivers.\n-pub struct Adapter<T: Driver>(T);\n+///\n+/// `F` is a [`ForLt`](trait@ForLt) type that maps lifetimes to the driver's device\n+/// private data type, i.e. `F::Of<'a>` is the driver struct parameterized by `'a`. The macro\n+/// `module_auxiliary_driver!` generates this automatically via `ForLt!()`.\n+pub struct Adapter<F>(PhantomData<F>);\n \n // SAFETY:\n // - `bindings::auxiliary_driver` is a C type declared as `repr(C)`.\n-// - `T` is the type of the driver's device private data.\n+// - `F::Of<'static>` is the stored type of the driver's device private data.\n // - `struct auxiliary_driver` embeds a `struct device_driver`.\n // - `DEVICE_DRIVER_OFFSET` is the correct byte offset to the embedded `struct device_driver`.\n-unsafe impl<T: Driver + 'static> driver::DriverLayout for Adapter<T> {\n+unsafe impl<F> driver::DriverLayout for Adapter<F>\n+where\n+    F: ForLt + 'static,\n+    for<'a> F::Of<'a>: Driver<'a>,\n+{\n     type DriverType = bindings::auxiliary_driver;\n-    type DriverData = ForLt!(T);\n+    type DriverData = F;\n     const DEVICE_DRIVER_OFFSET: usize = core::mem::offset_of!(Self::DriverType, driver);\n }\n \n // SAFETY: A call to `unregister` for a given instance of `DriverType` is guaranteed to be valid if\n // a preceding call to `register` has been successful.\n-unsafe impl<T: Driver + 'static> driver::RegistrationOps for Adapter<T> {\n+unsafe impl<F> driver::RegistrationOps for Adapter<F>\n+where\n+    F: ForLt + 'static,\n+    for<'a> F::Of<'a>: Driver<'a>,\n+{\n     unsafe fn register(\n         adrv: &Opaque<Self::DriverType>,\n         name: &'static CStr,\n@@ -64,7 +76,7 @@ unsafe fn register(\n             (*adrv.get()).name = name.as_char_ptr();\n             (*adrv.get()).probe = Some(Self::probe_callback);\n             (*adrv.get()).remove = Some(Self::remove_callback);\n-            (*adrv.get()).id_table = T::ID_TABLE.as_ptr();\n+            (*adrv.get()).id_table = <F::Of<'static> as Driver<'static>>::ID_TABLE.as_ptr();\n         }\n \n         // SAFETY: `adrv` is guaranteed to be a valid `DriverType`.\n@@ -79,7 +91,11 @@ unsafe fn unregister(adrv: &Opaque<Self::DriverType>) {\n     }\n }\n \n-impl<T: Driver + 'static> Adapter<T> {\n+impl<F> Adapter<F>\n+where\n+    F: ForLt + 'static,\n+    for<'a> F::Of<'a>: Driver<'a>,\n+{\n     extern \"C\" fn probe_callback(\n         adev: *mut bindings::auxiliary_device,\n         id: *const bindings::auxiliary_device_id,\n@@ -93,12 +109,12 @@ extern \"C\" fn probe_callback(\n         // SAFETY: `DeviceId` is a `#[repr(transparent)`] wrapper of `struct auxiliary_device_id`\n         // and does not add additional invariants, so it's safe to transmute.\n         let id = unsafe { &*id.cast::<DeviceId>() };\n-        let info = T::ID_TABLE.info(id.index());\n \n         from_result(|| {\n-            let data = T::probe(adev, info);\n+            let info = <F::Of<'_> as Driver<'_>>::ID_TABLE.info(id.index());\n+            let data = <F::Of<'_> as Driver<'_>>::probe(adev, info);\n \n-            adev.as_ref().set_drvdata::<ForLt!(T)>(data)?;\n+            adev.as_ref().set_drvdata::<F>(data)?;\n             Ok(0)\n         })\n     }\n@@ -111,19 +127,21 @@ extern \"C\" fn remove_callback(adev: *mut bindings::auxiliary_device) {\n         let adev = unsafe { &*adev.cast::<Device<device::CoreInternal>>() };\n \n         // SAFETY: `remove_callback` is only ever called after a successful call to\n-        // `probe_callback`, hence it's guaranteed that `Device::set_drvdata()` has been called\n-        // and stored a `Pin<KBox<T>>`.\n-        let data = unsafe { adev.as_ref().drvdata_borrow::<ForLt!(T)>() };\n+        // `probe_callback`, hence it's guaranteed that drvdata has been set.\n+        let data = unsafe { adev.as_ref().drvdata_borrow::<F>() };\n \n-        T::unbind(adev, data);\n+        <F::Of<'_> as Driver<'_>>::unbind(adev, data);\n     }\n }\n \n /// Declares a kernel module that exposes a single auxiliary driver.\n #[macro_export]\n macro_rules! module_auxiliary_driver {\n-    ($($f:tt)*) => {\n-        $crate::module_driver!(<T>, $crate::auxiliary::Adapter<T>, { $($f)* });\n+    (type: $type:ty, $($rest:tt)*) => {\n+        $crate::module_driver!(<T>, $crate::auxiliary::Adapter<T>, {\n+            type: $crate::types::ForLt!($type),\n+            $($rest)*\n+        });\n     };\n }\n \n@@ -195,7 +213,7 @@ macro_rules! auxiliary_device_table {\n /// The auxiliary driver trait.\n ///\n /// Drivers must implement this trait in order to get an auxiliary driver registered.\n-pub trait Driver {\n+pub trait Driver<'a>: Send {\n     /// The type holding information about each device id supported by the driver.\n     ///\n     /// TODO: Use associated_type_defaults once stabilized:\n@@ -209,7 +227,10 @@ pub trait Driver {\n     /// Auxiliary driver probe.\n     ///\n     /// Called when an auxiliary device is matches a corresponding driver.\n-    fn probe(dev: &Device<device::Core>, id_info: &Self::IdInfo) -> impl PinInit<Self, Error>;\n+    fn probe(\n+        dev: &'a Device<device::Core>,\n+        id_info: &'a Self::IdInfo,\n+    ) -> impl PinInit<Self, Error> + 'a;\n \n     /// Auxiliary driver unbind.\n     ///\n@@ -221,7 +242,7 @@ pub trait Driver {\n     /// operations to gracefully tear down the device.\n     ///\n     /// Otherwise, release operations for driver resources should be performed in `Self::drop`.\n-    fn unbind(dev: &Device<device::Core>, this: Pin<&Self>) {\n+    fn unbind(dev: &'a Device<device::Core>, this: Pin<&'a Self>) {\n         let _ = (dev, this);\n     }\n }\ndiff --git a/samples/rust/rust_driver_auxiliary.rs b/samples/rust/rust_driver_auxiliary.rs\nindex f57b2b03adb6..d35963ac7fa4 100644\n--- a/samples/rust/rust_driver_auxiliary.rs\n+++ b/samples/rust/rust_driver_auxiliary.rs\n@@ -26,16 +26,19 @@\n kernel::auxiliary_device_table!(\n     AUX_TABLE,\n     MODULE_AUX_TABLE,\n-    <AuxiliaryDriver as auxiliary::Driver>::IdInfo,\n+    <AuxiliaryDriver as auxiliary::Driver<'_>>::IdInfo,\n     [(auxiliary::DeviceId::new(MODULE_NAME, AUXILIARY_NAME), ())]\n );\n \n-impl auxiliary::Driver for AuxiliaryDriver {\n+impl<'a> auxiliary::Driver<'a> for AuxiliaryDriver {\n     type IdInfo = ();\n \n     const ID_TABLE: auxiliary::IdTable<Self::IdInfo> = &AUX_TABLE;\n \n-    fn probe(adev: &auxiliary::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {\n+    fn probe(\n+        adev: &'a auxiliary::Device<Core>,\n+        _info: &'a Self::IdInfo,\n+    ) -> impl PinInit<Self, Error> + 'a {\n         dev_info!(\n             adev,\n             \"Probing auxiliary driver for auxiliary device with id={}\\n\",\n@@ -123,7 +126,8 @@ struct SampleModule {\n     #[allow(clippy::type_complexity)]\n     _pci_driver: driver::Registration<pci::Adapter<ForLt!(ParentDriver)>>,\n     #[pin]\n-    _aux_driver: driver::Registration<auxiliary::Adapter<AuxiliaryDriver>>,\n+    #[allow(clippy::type_complexity)]\n+    _aux_driver: driver::Registration<auxiliary::Adapter<ForLt!(AuxiliaryDriver)>>,\n }\n \n impl InPlaceModule for SampleModule {\n","prefixes":["13/24"]}