{"id":2229208,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229208/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20260427221155.2144848-6-dakr@kernel.org/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/1.1/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260427221155.2144848-6-dakr@kernel.org>","date":"2026-04-27T22:11:03","name":"[05/24] rust: driver: make Adapter trait lifetime-parameterized","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"351e1cc33f1fb1017f6918fe31e1da23ea7054df","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-pci/patch/20260427221155.2144848-6-dakr@kernel.org/mbox/","series":[{"id":501733,"url":"http://patchwork.ozlabs.org/api/1.1/series/501733/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=501733","date":"2026-04-27T22:10:58","name":"rust: device: Higher-Ranked Lifetime Types for device drivers","version":1,"mbox":"http://patchwork.ozlabs.org/series/501733/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2229208/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229208/checks/","tags":{},"headers":{"Return-Path":"\n <linux-pci+bounces-53273-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@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=BopU7sLk;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=104.64.211.4; helo=sin.lore.kernel.org;\n envelope-from=linux-pci+bounces-53273-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=\"BopU7sLk\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])\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 4g4Hr62wWVz1xrS\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 08:12:54 +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 3EE95300C35D\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 27 Apr 2026 22:12:40 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id CCE6D3AB26A;\n\tMon, 27 Apr 2026 22:12:39 +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 A848226F2BE;\n\tMon, 27 Apr 2026 22:12:39 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id AE6DBC19425;\n\tMon, 27 Apr 2026 22:12:33 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777327959; cv=none;\n b=kNaDRx+vHizcldBk9bTyT26pr84552ov2Rq9mhkp01VlY6+Om1yrKIrnJC8Rdh0cirn5cSRrM+1uKKSogFH0ZLkY53c5MzBIUkLM50wKsWnItd5Tx9F7oi7AKVzkt+IQhPsWZ3Gg9s+Z1bahgApduASKLvJ+EsDHD8KOztCcCxM=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777327959; c=relaxed/simple;\n\tbh=LHxKj2Sqgk+a3BT1FgcDoIHc1Tx9bGrGlwRiqgYkiCM=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=SQgPiCOR4CiyvihL8hlO7XnoTkwp+PmMHKwQpxK3xBKtKXXjzjlxho8ukK1GsJ2GyksP035xr+CQv8tCmKGJ8XDBJGwepTFwhIUIEJlrVmbQPrtLx7Mqktah2YCDDfOo0U6dYWsLSB0sgMYkMuSW3LbbftrMJlPj04e74H4z2c4=","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=BopU7sLk; 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=1777327959;\n\tbh=LHxKj2Sqgk+a3BT1FgcDoIHc1Tx9bGrGlwRiqgYkiCM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=BopU7sLkdBecu6RzsUKESdx7jKEorWFsjYHninRucrKzOsyfaIZxAnbqOXmsf78yA\n\t LmBdvjlPHJ97CZ3/RZFmbxtU/RuVlMvkjTGHeIFrwlvhMgK2HPW6Rrym9ig+Kg/QTQ\n\t xcRNBDNx2WH4AgWRSd2W2W5BkQBYSPhfArdATJ+MhZUf3RGa4k1d+M/Pvkp8a/Ww6p\n\t 3Zv6Vz+kqxpkom45ckoM2Sf3kOI9wASJPg8k0aANf6FSFjcEg1HtidmpZK5UhjWmu8\n\t N46jRAPCJSQNUMHtm8CK2gtUrh0gGJdFLV7OXWW/i1SOHOSTeGmvoLbqBN476do3CH\n\t GhapsOt446RNw==","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 05/24] rust: driver: make Adapter trait lifetime-parameterized","Date":"Tue, 28 Apr 2026 00:11:03 +0200","Message-ID":"<20260427221155.2144848-6-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-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"Parameterize the Adapter trait with a lifetime, changing the id_info(),\nof_id_info() and acpi_id_info() methods to take &'a Device<Bound> and\nreturn &'a Self::IdInfo instead of &'static.\n\nThis is needed for the ForLt conversion of bus driver traits. Once\nDriver becomes lifetime-parameterized, its IdInfo associated type may\ndepend on the lifetime parameter. With Adapter<'a>, the impl can set\nIdInfo = <F::Of<'a> as Driver<'a>>::IdInfo and the lifetime flows\nthrough naturally, avoiding the need for transmute.\n\nFor the current non-lifetime-parameterized Driver trait, this is a no-op\ntype relaxation; IdInfo is 'static and &'static coerces to &'a.\n\nSigned-off-by: Danilo Krummrich <dakr@kernel.org>\n---\n rust/kernel/driver.rs   | 16 ++++++++++------\n rust/kernel/i2c.rs      | 10 +++++-----\n rust/kernel/platform.rs |  4 ++--\n 3 files changed, 17 insertions(+), 13 deletions(-)","diff":"diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs\nindex 29a67b12c872..91490040d77e 100644\n--- a/rust/kernel/driver.rs\n+++ b/rust/kernel/driver.rs\n@@ -96,7 +96,11 @@\n \n use crate::{\n     acpi,\n-    device,\n+    device::{\n+        self,\n+        Bound,\n+        Device, //\n+    },\n     of,\n     prelude::*,\n     types::{\n@@ -192,7 +196,7 @@ extern \"C\" fn post_unbind_callback(dev: *mut bindings::device) {\n         // a `struct device`.\n         //\n         // INVARIANT: `dev` is valid for the duration of the `post_unbind_callback()`.\n-        let dev = unsafe { &*dev.cast::<device::Device<device::CoreInternal>>() };\n+        let dev = unsafe { &*dev.cast::<Device<device::CoreInternal>>() };\n \n         // `remove()` has been completed at this point; devres resources are still valid and will\n         // be released after the driver's bus device private data is dropped.\n@@ -289,7 +293,7 @@ fn init(\n /// of a device and a driver.\n ///\n /// It provides bus independent functions for device / driver interactions.\n-pub trait Adapter {\n+pub trait Adapter<'a> {\n     /// The type holding driver private data about each device id supported by the driver.\n     type IdInfo: 'static;\n \n@@ -299,7 +303,7 @@ pub trait Adapter {\n     /// Returns the driver's private data from the matching entry in the [`acpi::IdTable`], if any.\n     ///\n     /// If this returns `None`, it means there is no match with an entry in the [`acpi::IdTable`].\n-    fn acpi_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {\n+    fn acpi_id_info(dev: &'a Device<Bound>) -> Option<&'a Self::IdInfo> {\n         #[cfg(not(CONFIG_ACPI))]\n         {\n             let _ = dev;\n@@ -333,7 +337,7 @@ fn acpi_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {\n     /// Returns the driver's private data from the matching entry in the [`of::IdTable`], if any.\n     ///\n     /// If this returns `None`, it means there is no match with an entry in the [`of::IdTable`].\n-    fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {\n+    fn of_id_info(dev: &'a Device<Bound>) -> Option<&'a Self::IdInfo> {\n         #[cfg(not(CONFIG_OF))]\n         {\n             let _ = dev;\n@@ -369,7 +373,7 @@ fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {\n     ///\n     /// If this returns `None`, it means that there is no match in any of the ID tables directly\n     /// associated with a [`device::Device`].\n-    fn id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {\n+    fn id_info(dev: &'a Device<Bound>) -> Option<&'a Self::IdInfo> {\n         let id = Self::acpi_id_info(dev);\n         if id.is_some() {\n             return id;\ndiff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs\nindex cde3dd7a6cc7..08d310aa9d6b 100644\n--- a/rust/kernel/i2c.rs\n+++ b/rust/kernel/i2c.rs\n@@ -162,8 +162,8 @@ extern \"C\" fn probe_callback(idev: *mut bindings::i2c_client) -> kernel::ffi::c_\n         // INVARIANT: `idev` is valid for the duration of `probe_callback()`.\n         let idev = unsafe { &*idev.cast::<I2cClient<device::CoreInternal>>() };\n \n-        let info =\n-            Self::i2c_id_info(idev).or_else(|| <Self as driver::Adapter>::id_info(idev.as_ref()));\n+        let info = Self::i2c_id_info(idev)\n+            .or_else(|| <Self as driver::Adapter<'_>>::id_info(idev.as_ref()));\n \n         from_result(|| {\n             let data = T::probe(idev, info);\n@@ -198,14 +198,14 @@ extern \"C\" fn shutdown_callback(idev: *mut bindings::i2c_client) {\n     }\n \n     /// The [`i2c::IdTable`] of the corresponding driver.\n-    fn i2c_id_table() -> Option<IdTable<<Self as driver::Adapter>::IdInfo>> {\n+    fn i2c_id_table() -> Option<IdTable<<Self as driver::Adapter<'static>>::IdInfo>> {\n         T::I2C_ID_TABLE\n     }\n \n     /// Returns the driver's private data from the matching entry in the [`i2c::IdTable`], if any.\n     ///\n     /// If this returns `None`, it means there is no match with an entry in the [`i2c::IdTable`].\n-    fn i2c_id_info(dev: &I2cClient) -> Option<&'static <Self as driver::Adapter>::IdInfo> {\n+    fn i2c_id_info(dev: &I2cClient) -> Option<&'static <Self as driver::Adapter<'static>>::IdInfo> {\n         let table = Self::i2c_id_table()?;\n \n         // SAFETY:\n@@ -225,7 +225,7 @@ fn i2c_id_info(dev: &I2cClient) -> Option<&'static <Self as driver::Adapter>::Id\n     }\n }\n \n-impl<T: Driver + 'static> driver::Adapter for Adapter<T> {\n+impl<'a, T: Driver + 'static> driver::Adapter<'a> for Adapter<T> {\n     type IdInfo = T::IdInfo;\n \n     fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> {\ndiff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs\nindex 7ff69e3eea90..1585b6a1ac45 100644\n--- a/rust/kernel/platform.rs\n+++ b/rust/kernel/platform.rs\n@@ -101,7 +101,7 @@ extern \"C\" fn probe_callback(pdev: *mut bindings::platform_device) -> kernel::ff\n         //\n         // INVARIANT: `pdev` is valid for the duration of `probe_callback()`.\n         let pdev = unsafe { &*pdev.cast::<Device<device::CoreInternal>>() };\n-        let info = <Self as driver::Adapter>::id_info(pdev.as_ref());\n+        let info = <Self as driver::Adapter<'_>>::id_info(pdev.as_ref());\n \n         from_result(|| {\n             let data = T::probe(pdev, info);\n@@ -127,7 +127,7 @@ extern \"C\" fn remove_callback(pdev: *mut bindings::platform_device) {\n     }\n }\n \n-impl<T: Driver + 'static> driver::Adapter for Adapter<T> {\n+impl<'a, T: Driver + 'static> driver::Adapter<'a> for Adapter<T> {\n     type IdInfo = T::IdInfo;\n \n     fn of_id_table() -> Option<of::IdTable<Self::IdInfo>> {\n","prefixes":["05/24"]}