{"id":2229206,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229206/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pwm/patch/20260427221155.2144848-2-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-2-dakr@kernel.org>","date":"2026-04-27T22:10:59","name":"[01/24] rust: driver core: drop drvdata before devres release","commit_ref":null,"pull_url":null,"state":"handled-elsewhere","archived":false,"hash":"6d020f63776cd9000cd3e917b22e0a96bb1a88e5","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-2-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/2229206/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229206/checks/","tags":{},"headers":{"Return-Path":"\n <linux-pwm+bounces-8704-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=B0DI94d2;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.234.253.10; helo=sea.lore.kernel.org;\n envelope-from=linux-pwm+bounces-8704-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=\"B0DI94d2\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=10.30.226.201"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4Hqy21xgz1xrS\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 08:12:46 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 2AE9730209D5\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 27 Apr 2026 22:12:15 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id C16A33A6B81;\n\tMon, 27 Apr 2026 22:12:14 +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 9D09226F2BE;\n\tMon, 27 Apr 2026 22:12:14 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id 9F904C19425;\n\tMon, 27 Apr 2026 22:12:08 +0000 (UTC)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777327934; cv=none;\n b=c3eckqKjr15VOdAf+CsfstMljBZdQBWpENWpGfqrAxSZVFa3g9o96fHkbSIfEHqEvU0/eSj0K1QKMZVmxQR1Ae7M6YIMW+MmyrLtQ47XAw+nY69bbA872jBXlmxEi8AgJfXQRaz/kJwwKQQh6cHHInYdhXHjcFSJCVMlYOe+T7g=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777327934; c=relaxed/simple;\n\tbh=ju+F7o8Yl0nyozmN8SThTNujs1B0GOs/rWyZh4FMitg=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=K7jRC9E0QPx4ICGqiA3JeTPrkoLcMYfmwj74Aq0vp/hDTJZhwABw7V/zpOrVtmYU6OgJ32sSE3p54HAushcwMnTEXfmCdA21eZ/zA40DDQTKJ6+AMXWBJlGfu8b2HSOSTtuyS2K8+hqSegopyk5coW4X2Vsdrj2koa01TD/+TeM=","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=B0DI94d2; 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=1777327934;\n\tbh=ju+F7o8Yl0nyozmN8SThTNujs1B0GOs/rWyZh4FMitg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=B0DI94d2eRFKDr3/VwZbkkFsvz36IGsGDJhc8SmdCK5Z5cARqCTNNFlEfE9EwcpKg\n\t IqSQS7X0la8Qy4Uu9wC5Z47YmGqMDrIdAB6CIl7Kk2CYVGhaghWLzWUiChXNp6wGK3\n\t sGHygogvD8WI7CopuAM5NyRz9NXzAEZ2ipxldU+Ssx0W/HgaH3OWWeAc2NDKawW9FY\n\t NY9+I9h8GlXTG1y/UVjx2uovH8iyQ0xKNgmXJQmPg844taSQlRztSkbNfwkrxs9aY1\n\t IyaoJNYxpsYna35Tk2JTSso2ezu9t73QM1O73Zhb6F2DLvze3BSEujdZ+SjyNc+Zjd\n\t 7nyxZcE1D64lQ==","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 01/24] rust: driver core: drop drvdata before devres release","Date":"Tue, 28 Apr 2026 00:10:59 +0200","Message-ID":"<20260427221155.2144848-2-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":"Move the post_unbind_rust callback before devres_release_all() in\ndevice_unbind_cleanup().\n\nWith drvdata() removed, the driver's bus device private data is only\naccessible by the owning driver itself. It is hence safe to drop the\ndriver's bus device private data before devres actions are released.\n\nThis reordering is the key enabler for Higher-Ranked Lifetime Types\n(HRT) in Rust device drivers -- it allows driver structs to hold direct\nreferences to devres-managed resources, because the bus device private\ndata (and with it all such references) is guaranteed to be dropped while\nthe underlying devres resources are still alive.\n\nWithout this change, devres resources would be freed first, leaving the\ndriver's bus device private data with dangling references during its\ndestructor.\n\nSigned-off-by: Danilo Krummrich <dakr@kernel.org>\n---\n drivers/base/dd.c             | 2 +-\n include/linux/device/driver.h | 4 ++--\n rust/kernel/driver.rs         | 4 ++--\n 3 files changed, 5 insertions(+), 5 deletions(-)","diff":"diff --git a/drivers/base/dd.c b/drivers/base/dd.c\nindex 5799a60fd058..be59d2e13a15 100644\n--- a/drivers/base/dd.c\n+++ b/drivers/base/dd.c\n@@ -593,9 +593,9 @@ static DEVICE_ATTR_RW(state_synced);\n \n static void device_unbind_cleanup(struct device *dev)\n {\n-\tdevres_release_all(dev);\n \tif (dev->driver->p_cb.post_unbind_rust)\n \t\tdev->driver->p_cb.post_unbind_rust(dev);\n+\tdevres_release_all(dev);\n \tarch_teardown_dma_ops(dev);\n \tkfree(dev->dma_range_map);\n \tdev->dma_range_map = NULL;\ndiff --git a/include/linux/device/driver.h b/include/linux/device/driver.h\nindex bbc67ec513ed..38e9a4679447 100644\n--- a/include/linux/device/driver.h\n+++ b/include/linux/device/driver.h\n@@ -123,8 +123,8 @@ struct device_driver {\n \tstruct driver_private *p;\n \tstruct {\n \t\t/*\n-\t\t * Called after remove() and after all devres entries have been\n-\t\t * processed. This is a Rust only callback.\n+\t\t * Called after remove() but before devres entries are released.\n+\t\t * This is a Rust only callback.\n \t\t */\n \t\tvoid (*post_unbind_rust)(struct device *dev);\n \t} p_cb;\ndiff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs\nindex 36de8098754d..8f0e50729215 100644\n--- a/rust/kernel/driver.rs\n+++ b/rust/kernel/driver.rs\n@@ -189,8 +189,8 @@ extern \"C\" fn post_unbind_callback(dev: *mut bindings::device) {\n         // INVARIANT: `dev` is valid for the duration of the `post_unbind_callback()`.\n         let dev = unsafe { &*dev.cast::<device::Device<device::CoreInternal>>() };\n \n-        // `remove()` and all devres callbacks have been completed at this point, hence drop the\n-        // driver's device private data.\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         //\n         // SAFETY: By the safety requirements of the `Driver` trait, `T::DriverData` is the\n         // driver's device private data type.\n","prefixes":["01/24"]}