Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2229219/?format=api
{ "id": 2229219, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2229219/?format=api", "web_url": "http://patchwork.ozlabs.org/project/linux-pwm/patch/20260427221155.2144848-17-dakr@kernel.org/", "project": { "id": 38, "url": "http://patchwork.ozlabs.org/api/1.1/projects/38/?format=api", "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-17-dakr@kernel.org>", "date": "2026-04-27T22:11:14", "name": "[16/24] rust: usb: make Driver trait lifetime-parameterized", "commit_ref": null, "pull_url": null, "state": "handled-elsewhere", "archived": false, "hash": "24774fb6b46aa05142045180d768dac846cc8b4b", "submitter": { "id": 89037, "url": "http://patchwork.ozlabs.org/api/1.1/people/89037/?format=api", "name": "Danilo Krummrich", "email": "dakr@kernel.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/linux-pwm/patch/20260427221155.2144848-17-dakr@kernel.org/mbox/", "series": [ { "id": 501734, "url": "http://patchwork.ozlabs.org/api/1.1/series/501734/?format=api", "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/2229219/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2229219/checks/", "tags": {}, "headers": { "Return-Path": "\n <linux-pwm+bounces-8719-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=aFiYEfVB;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c09:e001:a7::12fc:5321; helo=sto.lore.kernel.org;\n envelope-from=linux-pwm+bounces-8719-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=\"aFiYEfVB\"", "smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201" ], "Received": [ "from sto.lore.kernel.org (sto.lore.kernel.org\n [IPv6:2600:3c09:e001:a7::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 4g4Hv95mLwz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 08:15:33 +1000 (AEST)", "from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sto.lore.kernel.org (Postfix) with ESMTP id D9FEF301FC30\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 27 Apr 2026 22:14:26 +0000 (UTC)", "from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 908CB3ACF13;\n\tMon, 27 Apr 2026 22:13:49 +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 6ACA43AB262;\n\tMon, 27 Apr 2026 22:13:49 +0000 (UTC)", "by smtp.kernel.org (Postfix) with ESMTPSA id 410D6C2BCB6;\n\tMon, 27 Apr 2026 22:13:43 +0000 (UTC)" ], "ARC-Seal": "i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777328029; cv=none;\n b=K7d6IxoE7DrnrwGqc3vVz1T4wCRMxUC33dnm0dVwCwxoZdHqFEpjsdJ0YM96EG2b9b9bcP0/NFA7UpWboycJ5vfJLntUNdiJsqfWOw4ad0jCFJFX+P/iMjtzXH9usXNy5Ll9U6is/2gN5mgLK/Y7KGYRd91Qygzte7qR21FIU9w=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777328029; c=relaxed/simple;\n\tbh=LqoJmyLMcfvlHKDJq6T+tkDE6stHA+a+dnj6GefZ9os=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=JeJvrDbN6o3nxFjS0YwoYqR3LHJKn+NczTQ8ZBnIS9SdK8a7Wuc/sZYhqyKFPN0hpL6RKVwnJ8BPGjUGD0eZPl/gr+6MZmuz1q1MYy4UNTfMNBhYHNYHYTzgHeE4V0qAoJBGQ4Bce9C1wbBa3b/wAkraWhDX/cyEjw+pHx2yRic=", "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=aFiYEfVB; 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=1777328029;\n\tbh=LqoJmyLMcfvlHKDJq6T+tkDE6stHA+a+dnj6GefZ9os=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=aFiYEfVByRv2PjDa9rjYPjgR9q/fQlaBcDWAP+n9ARzSi35I3fnQBQL4jXkKGDFqb\n\t Z+VfYo+FSkRbNwQd6HzuNL2R+VKCaOPP2Vt7a5oRB1f1lN8QHUS7mkwa2kqHPVBPHD\n\t l03xRWXLrvCwYveEXJEMCVnnLbogwLsr1wkfNlkwlAmoq9F+HdY8YjBxU3qt84QonQ\n\t vdiQnv2fsuVsGsUCmq1lVdBEMwCQFAmiGn60q3rtrxY6WPr2VXXMG+6L4Xh1xwYO4V\n\t WJEmvDbKfwovia/wetB+zMtncjlIo7goJfWZX5JKqF73OCnqP5s8BCruWMyK6RvsV7\n\t duihnqd6v+KKw==", "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 16/24] rust: usb: make Driver trait lifetime-parameterized", "Date": "Tue, 28 Apr 2026 00:11:14 +0200", "Message-ID": "<20260427221155.2144848-17-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 usb::Driver take a lifetime parameter 'a that ties device resources\nto the binding scope.\n\nInternally, Adapter<T: Driver> becomes Adapter<F: ForLt> with a bound\nfor<'a> F::Of<'a>: Driver<'a>; module_usb_driver! wraps the driver type\nin ForLt!() so drivers don't have to.\n\nSigned-off-by: Danilo Krummrich <dakr@kernel.org>\n---\n rust/kernel/usb.rs | 84 ++++++++++++++++++++-------------\n samples/rust/rust_driver_usb.rs | 14 +++---\n 2 files changed, 58 insertions(+), 40 deletions(-)", "diff": "diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs\nindex 442e456fd2d3..f519444cf8d0 100644\n--- a/rust/kernel/usb.rs\n+++ b/rust/kernel/usb.rs\n@@ -35,22 +35,34 @@\n };\n \n /// An adapter for the registration of USB 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_usb_driver!` generates this automatically via `ForLt!()`.\n+pub struct Adapter<F>(PhantomData<F>);\n \n // SAFETY:\n // - `bindings::usb_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 usb_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::usb_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 udrv: &Opaque<Self::DriverType>,\n name: &'static CStr,\n@@ -61,7 +73,7 @@ unsafe fn register(\n (*udrv.get()).name = name.as_char_ptr();\n (*udrv.get()).probe = Some(Self::probe_callback);\n (*udrv.get()).disconnect = Some(Self::disconnect_callback);\n- (*udrv.get()).id_table = T::ID_TABLE.as_ptr();\n+ (*udrv.get()).id_table = <F::Of<'static> as Driver<'static>>::ID_TABLE.as_ptr();\n }\n \n // SAFETY: `udrv` is guaranteed to be a valid `DriverType`.\n@@ -76,7 +88,11 @@ unsafe fn unregister(udrv: &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 intf: *mut bindings::usb_interface,\n id: *const bindings::usb_device_id,\n@@ -87,16 +103,16 @@ extern \"C\" fn probe_callback(\n // INVARIANT: `intf` is valid for the duration of `probe_callback()`.\n let intf = unsafe { &*intf.cast::<Interface<device::CoreInternal>>() };\n \n- from_result(|| {\n- // SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `struct usb_device_id` and\n- // does not add additional invariants, so it's safe to transmute.\n- let id = unsafe { &*id.cast::<DeviceId>() };\n+ // SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `struct usb_device_id` and\n+ // does not add additional invariants, so it's safe to transmute.\n+ let id = unsafe { &*id.cast::<DeviceId>() };\n \n- let info = T::ID_TABLE.info(id.index());\n- let data = T::probe(intf, id, info);\n+ from_result(|| {\n+ let info = <F::Of<'_> as Driver<'_>>::ID_TABLE.info(id.index());\n+ let data = <F::Of<'_> as Driver<'_>>::probe(intf, id, info);\n \n let dev: &device::Device<device::CoreInternal> = intf.as_ref();\n- dev.set_drvdata::<ForLt!(T)>(data)?;\n+ dev.set_drvdata::<F>(data)?;\n Ok(0)\n })\n }\n@@ -111,11 +127,10 @@ extern \"C\" fn disconnect_callback(intf: *mut bindings::usb_interface) {\n let dev: &device::Device<device::CoreInternal> = intf.as_ref();\n \n // SAFETY: `disconnect_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 { dev.drvdata_borrow::<ForLt!(T)>() };\n+ // `probe_callback`, hence it's guaranteed that drvdata has been set.\n+ let data = unsafe { dev.drvdata_borrow::<F>() };\n \n- T::disconnect(intf, data);\n+ <F::Of<'_> as Driver<'_>>::disconnect(intf, data);\n }\n }\n \n@@ -281,29 +296,29 @@ macro_rules! usb_device_table {\n /// kernel::usb_device_table!(\n /// USB_TABLE,\n /// MODULE_USB_TABLE,\n-/// <MyDriver as usb::Driver>::IdInfo,\n+/// <MyDriver as usb::Driver<'_>>::IdInfo,\n /// [\n /// (usb::DeviceId::from_id(0x1234, 0x5678), ()),\n /// (usb::DeviceId::from_id(0xabcd, 0xef01), ()),\n /// ]\n /// );\n ///\n-/// impl usb::Driver for MyDriver {\n+/// impl<'a> usb::Driver<'a> for MyDriver {\n /// type IdInfo = ();\n /// const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;\n ///\n /// fn probe(\n-/// _interface: &usb::Interface<Core>,\n-/// _id: &usb::DeviceId,\n-/// _info: &Self::IdInfo,\n-/// ) -> impl PinInit<Self, Error> {\n+/// _interface: &'a usb::Interface<Core>,\n+/// _id: &'a usb::DeviceId,\n+/// _info: &'a Self::IdInfo,\n+/// ) -> impl PinInit<Self, Error> + 'a {\n /// Err(ENODEV)\n /// }\n ///\n-/// fn disconnect(_interface: &usb::Interface<Core>, _data: Pin<&Self>) {}\n+/// fn disconnect(_interface: &'a usb::Interface<Core>, _data: Pin<&'a Self>) {}\n /// }\n ///```\n-pub trait Driver {\n+pub trait Driver<'a> {\n /// The type holding information about each one of the device ids supported by the driver.\n type IdInfo: 'static;\n \n@@ -315,15 +330,15 @@ pub trait Driver {\n /// Called when a new USB interface is bound to this driver.\n /// Implementers should attempt to initialize the interface here.\n fn probe(\n- interface: &Interface<device::Core>,\n- id: &DeviceId,\n- id_info: &Self::IdInfo,\n- ) -> impl PinInit<Self, Error>;\n+ interface: &'a Interface<device::Core>,\n+ id: &'a DeviceId,\n+ id_info: &'a Self::IdInfo,\n+ ) -> impl PinInit<Self, Error> + 'a;\n \n /// USB driver disconnect.\n ///\n /// Called when the USB interface is about to be unbound from this driver.\n- fn disconnect(interface: &Interface<device::Core>, data: Pin<&Self>);\n+ fn disconnect(interface: &'a Interface<device::Core>, data: Pin<&'a Self>);\n }\n \n /// A USB interface.\n@@ -486,7 +501,10 @@ unsafe impl Sync for Device<device::Bound> {}\n /// ```\n #[macro_export]\n macro_rules! module_usb_driver {\n- ($($f:tt)*) => {\n- $crate::module_driver!(<T>, $crate::usb::Adapter<T>, { $($f)* });\n+ (type: $type:ty, $($rest:tt)*) => {\n+ $crate::module_driver!(<T>, $crate::usb::Adapter<T>, {\n+ type: $crate::types::ForLt!($type),\n+ $($rest)*\n+ });\n }\n }\ndiff --git a/samples/rust/rust_driver_usb.rs b/samples/rust/rust_driver_usb.rs\nindex ab72e99e1274..6f3e5db9f35d 100644\n--- a/samples/rust/rust_driver_usb.rs\n+++ b/samples/rust/rust_driver_usb.rs\n@@ -20,26 +20,26 @@ struct SampleDriver {\n kernel::usb_device_table!(\n USB_TABLE,\n MODULE_USB_TABLE,\n- <SampleDriver as usb::Driver>::IdInfo,\n+ <SampleDriver as usb::Driver<'_>>::IdInfo,\n [(usb::DeviceId::from_id(0x1234, 0x5678), ()),]\n );\n \n-impl usb::Driver for SampleDriver {\n+impl<'a> usb::Driver<'a> for SampleDriver {\n type IdInfo = ();\n const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;\n \n fn probe(\n- intf: &usb::Interface<Core>,\n- _id: &usb::DeviceId,\n- _info: &Self::IdInfo,\n- ) -> impl PinInit<Self, Error> {\n+ intf: &'a usb::Interface<Core>,\n+ _id: &'a usb::DeviceId,\n+ _info: &'a Self::IdInfo,\n+ ) -> impl PinInit<Self, Error> + 'a {\n let dev: &device::Device<Core> = intf.as_ref();\n dev_info!(dev, \"Rust USB driver sample probed\\n\");\n \n Ok(Self { _intf: intf.into() })\n }\n \n- fn disconnect(intf: &usb::Interface<Core>, _data: Pin<&Self>) {\n+ fn disconnect(intf: &'a usb::Interface<Core>, _data: Pin<&'a Self>) {\n let dev: &device::Device<Core> = intf.as_ref();\n dev_info!(dev, \"Rust USB driver sample disconnected\\n\");\n }\n", "prefixes": [ "16/24" ] }