From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2B7F46C4B4 for ; Mon, 5 Oct 2026 09:47:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791193676; cv=none; b=R7Wlag3pUfuTBkoFwZXpqJP0lEDNufL1/DHVsnT4BrFC4lH87K9pfJTPSaJ8LrxkTH0NYg3rmT/JseyqaufOiiWhlRntC/f49WKvk4T93j2CgGuFh5/MFH2cycwJL76VeDrj377WCZHbxWebo01ymOUhd4FE30jS4t/IvnXtkvs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791193676; c=relaxed/simple; bh=C/HalkpVc/aaLPRcuY8K3fmDX5xNBnpE2HlADon4V+4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PwNdG/e9Lh/9TZFp6pq1CH7vSRAlmSxtT7rKs8GsL1LzWf7AcutMBAlWzTBAfprtEi99dZ/O12XQjuhqz3j3djJUqy2Pkusbjd7GecU9GYDda+h/KdIfKF1FrZfIiBuyMH4KZ25ORQqKnOAm9NAeQkYJPPlGNgx8Q4UrhaMgsCg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SBf94Xq3; arc=none smtp.client-ip=209.85.221.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SBf94Xq3" Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4870142f030so990012f8f.2 for ; Mon, 05 Oct 2026 02:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1791193664; x=1791798464; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BbsBB7teGYK9VKfbxNuqfeRouM1sExnVepBnTLGc54E=; b=SBf94Xq3RDkh/2auYXT3fbWcadjJC6vDOa82FcbqK9VBd85xGBwwdDVJ26VbHZu1hD cAveRO9FJMVjUISgtHFrJivbhF3N2KGmnKsdTquGdLbzF8pwAdTRmFpBvQYUh1Q/5eVP 18jFn7cK3O5Y4v5xdXUwndbVAcZb7E1Uglx9jYCVVZV624uf5XHs7oQlcPgsqHkbbf/a UjenayaNSCfLX56ZJuSQLMu90o2c2gZJdvQjgpMfMF7D4gj0RD7d/R7o8eUYlxjxWHVH hEaxFQVMeY+I8S1iyPiPZmRZu6+qZYwo6Qnl/mGLpzRQ5UDcGuLBiEK3ZG0OTJmCTGtQ 29nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791193664; x=1791798464; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BbsBB7teGYK9VKfbxNuqfeRouM1sExnVepBnTLGc54E=; b=zWgXhxCbDhcupIGn958QZuOZzpM3OMUL5WNdU2BKr+lC5iioNqjrwKiNgcXU5eyZiy N79Ct+T/ub0QfYUMmi7nLbKElZEjwp/7J0m5K9jx6Hbyu1i1mfb5uGN4PoaRq+BwvYfM xutFryNiAAfw0IDUHAKfjbJiLvi9ZvbAXVAX5rqhxvAl3ynFr4BImhrsP278F1yK1yv+ SKYtrPxpP7CMyKJYC0jyqUW5ycy/xm7MZbibXFuOlf5a63v+DXXDchtte2DxIvD4eLvC 6wl+F0mwfSTgjqpbkAU+bOzqqMeCBaivLq/1LGNsTIlSKj001yrk0oeVqSfT5DEr7Wxp j/vQ== X-Forwarded-Encrypted: i=1; AKwUvBzKjQvjfB5As8WGta7NELDQJ05txCvBWbA5QN3Tb4KhKjtKJEkyscNoBQiOr4AQFMBkR2TL6zN91MBei6c=@vger.kernel.org X-Gm-Message-State: AFuF++nGkVYPvUxnwmLEfUEJm0rHN1mgvI3ukliG79RT3u25KCpYEkab l+9rqwerE/9zlWZCBMyjZIjrWEMJ1jnUO6XMujJw6mfbKTAx6GGQ/5+rDuenG8JuaEbIHBcvyeV 5EaCUxCKAxszoLHqH+A== X-Received: from wmpl19.prod.google.com ([2002:a05:600c:893:b0:4a1:6fa9:2d03]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:6215:b0:49d:1fd8:b874 with SMTP id 5b1f17b1804b1-4a027564c86mr168001755e9.19.1791193663635; Mon, 05 Oct 2026 02:47:43 -0700 (PDT) Date: Mon, 05 Oct 2026 09:47:27 +0000 In-Reply-To: <20261005-devres-6-18-backport-v1-0-06dcf0e592d5@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20261005-devres-6-18-backport-v1-0-06dcf0e592d5@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=2136; i=aliceryhl@google.com; h=from:subject:message-id; bh=/W9/p/qUlI7c+Vp8Q94K4vcY+BU6ZQPqrD1mg6wzcFI=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBqw3I6RxE3WbmZPE+KA8VBS08Df1RqphB6A+wPj scmipIk34iJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCasNyOgAKCRAEWL7uWMY5 RkT2D/4lM2bD7ln830RsI8zOjVjIR67yUnU1DOiP9PrXWtmyiLUgjij5MZRBRIFuxJ9MaXwC747 mV7kskmGyj9uvZFKnJvyzRUYg4t/1zG45ODmg1PwVqaAHElsUhsSqC/vhurzgOE3P7k/UdqHRB1 5xuLtTCsYG2ZM9fhMNXCcpHnySjRrAHLuv16C7LfEG9tULS6gRbxa77D+znu8NeBYFdofyrWMkZ wIOv6cCyulWeWtOY8ptqMLgxI/lmevH+lQyE7vlEUW4cutcS5Xg0geBO9p1u9ifKkk+SP39gu7m dVJG/yw5yYWS3tC2NeCBGalAafbmhlcqwLn5eEQNm0E23dbMfp+1hoi+spu0AeZSF4IDmeUaQla OnI5/sxYs342CQgdxiq8IlQZTMDnkrXjkXc9Tylyl7kh1pjyeX8cRPCl4usrCHbmDaA943Qp6ZE PYRmxGGBI1RKy817zvidz9/AuaUfBLLIFAnuUB1/hQWI6lWLt4cq9yoP6BmUu126iNH8nAYSGtX F7w44ofCMUPStjRl0gggtKU3fBe3NY4mtT6+pSOVR7Z+/v03P7ObrTDZs9q0KOW83F5a84QZS0f 81CirftdX1+uJMqIe4Kd9EUMxel7HntoeH+Jofo+eVsZqNOeFcc2r5gMQZlQnRFK6t5tjw5W0Y9 j7QQ147Cn4UOvcw== X-Mailer: b4 0.14.3 Message-ID: <20261005-devres-6-18-backport-v1-2-06dcf0e592d5@google.com> Subject: [PATCH 6.18.y 2/5] rust: devres: add 'static bound to Devres From: Alice Ryhl To: stable@vger.kernel.org, Greg Kroah-Hartman , Sasha Levin , Danilo Krummrich Cc: Alexandre Courbot , Andreas Hindborg , Benno Lossin , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Boqun Feng , Boris Brezillon , Daniel Almeida , Eliot Courtney , Gary Guo , Markus Probst , Miguel Ojeda , "Rafael J. Wysocki" , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" From: Danilo Krummrich commit 016267b521b18529c977c9eca9597a1669c3d73c upstream. Devres::new() registers a callback with the C devres subsystem via devres_node_add(). If the Devres is leaked (e.g. via core::mem::forget(), which is safe), its Drop impl never runs, and the devres release callback will revoke the inner Revocable on device unbind, which drops T in place. If T contains non-'static references, those may be dangling by that point. Add a 'static bound to prevent storing types with borrowed data in Devres. Fixes: 76c01ded724b ("rust: add devres abstraction") Reviewed-by: Alexandre Courbot Reviewed-by: Eliot Courtney Link: https://patch.msgid.link/20260526000447.350558-1-dakr@kernel.org Signed-off-by: Danilo Krummrich Signed-off-by: Alice Ryhl --- rust/kernel/devres.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index 562dd54fbe43..0fea4f2844a5 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -97,7 +97,7 @@ /// # Ok(()) /// # } /// ``` -pub struct Devres { +pub struct Devres { dev: ARef, /// Pointer to [`Self::devres_callback`]. /// @@ -107,7 +107,7 @@ pub struct Devres { data: Arc>, } -impl Devres { +impl Devres { /// Creates a new [`Devres`] instance of the given `data`. /// /// The `data` encapsulated within the returned `Devres` instance' `data` will be @@ -236,7 +236,7 @@ unsafe impl Send for Devres {} // SAFETY: `Devres` can be shared with any task, if `T: Sync`. unsafe impl Sync for Devres {} -impl Drop for Devres { +impl Drop for Devres { fn drop(&mut self) { // SAFETY: When `drop` runs, it is guaranteed that nobody is accessing the revocable data // anymore, hence it is safe not to wait for the grace period to finish. -- 2.56.0.360.g66cac248cb-goog