From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=117.135.210.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796044689; b=Y3E5G2ECakmTCTYJEjR7ByeNfX2gP2UA7VnXQCTqmcblFk4aFP14T7xRmtnjechNlxHm 6jtWeUHqDNktpb1O3FWqwiC/LAI5lF0pcQC1A93aY0En0kFAfcG3WLFIe3p3PkQeFPRSl t/fOR7KCC8EVzTUG5TbpiE/tuUoQhziIzI0kBGaB++tCL+ZAQIPYNf9T//Fq2NMV+I1bV VrKcmBn9GFTZLGBbT9XrIiLjA/Axu0dI3Npr4G9IViuhFaPr+BlBHhjpNFp01TaXLo3Wp kgt4UBodzR2Xwxm8PoaU3J44UsV/8ZBbQ8Fx4Lu8E1OXOaFhU8FnQZP//QQIGo2PpTw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796044689; h=DMARC-Filter:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: Content-Type:Content-Transfer-Encoding:MIME-Version:X-CM-TRANSID: X-Coremail-Antispam:X-CM-SenderInfo; bh=MDcuYBMattxsJCdtLT1KxvSbfM6n61PPSe9HmP/1x48=; b=1yK4ulB2eWLz/maL+yhKWg/2i9jxYFRrRrAyx3Z0fc+PRbzDQUZsD3rpVfoe3XEO8L8n /MP5N+orsJxbDR1/9aEEY3PlhLjNSBSSxuWBhU+89ht/0qlGY9MD01FVVrRmwuJhUjdac Xbga7F90LGujS1XceEDmhLYezNkJ3o/HfUAdhsWAD9NIMc+B8hK5HlkYqXKxDMZauaQdw CesmsXkeUhDJlwElKcMMeCPTZol9ZjomyZ+yDr5hfIKx1x/7uW0hKjviDTF+oeWidH2vD 0r2EqoX/qKDnGFsxsQ4JYafeRjgerlkd8/Rf+7poTgbj0gAnWjlRq46BR1G+gBE/Nhw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=kJ1kDjV9; arc=none smtp.remote-ip=117.135.210.9 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF898606A332; Mon, 30 Nov 2026 13:18:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AF898606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=kJ1kDjV9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:To:Subject:Date:Message-ID:Content-Type: MIME-Version; bh=MDcuYBMattxsJCdtLT1KxvSbfM6n61PPSe9HmP/1x48=; b=kJ1kDjV9BV2mOlXaqN1QtNhA1Ulx+6DH3IPf5SVJ2hg1Mn4Uul0kNvIiJNBnm1 G2bTi6kb7x5y9qSHkO+unlesFozCozEw4DdfajMIkt++N2lr59qIopFCkKEneZL2 Yu2xAFaCQyLH7UM+vCtkHCqP0Xyf8nsOlVS7t/gcqIWlI= From: Bilal Hashim To: Viresh Kumar , "Rafael J. Wysocki" Cc: Zhongqiu Han , Miguel Ojeda , Alice Ryhl , linux-pm@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] rust: opp: clone cpumask before adding OF table in from_of_cpumask() Date: Mon, 30 Nov 2026 21:17:24 +0800 Message-ID: <179604464473.13032.3572169864639839233@126.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-CM-TRANSID:_____wDnVyRldw1rJ+dtEQ--.45665S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tFyrur45tw1xXrW5Kr48WFg_yoW8WrW8pr yUJFWUtrWYgFyxG34DXa1Igry8G3ykX34vyw4UJ3yFva4fCw18tr1qqa1ag3WDG395Gr1F vryqgF4aqa4UA3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jUzVbUUUUU= X-CM-SenderInfo: 5dhh2vbf6rjloofrz/xtbBrAgWsGsNd2h99AAA3y In Table::from_of_cpumask(), CpumaskVar::try_clone(cpumask) is currently called after bindings::dev_pm_opp_of_cpumask_add_table() succeeds. If the cpumask allocation fails, Table is dropped before table.cpus is set, so Drop does not call dev_pm_opp_of_cpumask_remove_table() and the C-side cpumask OPP table is leaked. Clone the cpumask before calling dev_pm_opp_of_cpumask_add_table() so that an allocation failure returns cleanly without leaking the OPP table. Fixes: d52c7e868fbc ("rust: opp: Add abstractions for the OPP table") Signed-off-by: Bilal Hashim --- Changes in v2: - Drop the unreachable Self::from_dev() error rollback hunks in Table::from_of() and Table::from_of_cpumask() and keep only the CpumaskVar::try_clone() move (thanks to Zhongqiu Han). - Update commit message and add Fixes: tag. --- rust/kernel/opp.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs index 62e4467..1236ce3 100644 --- a/rust/kernel/opp.rs +++ b/rust/kernel/opp.rs @@ -687,6 +687,8 @@ impl Table { /// entries. #[cfg(CONFIG_OF)] pub fn from_of_cpumask(dev: &Device, cpumask: &mut Cpumask) -> Result { + let cpus = CpumaskVar::try_clone(cpumask)?; + // SAFETY: The cpumask is valid and the returned pointer will be owned by the [`Table`] // instance. // @@ -696,7 +698,7 @@ impl Table { // Fetch the newly created table. let mut table = Self::from_dev(dev)?; - table.cpus = Some(CpumaskVar::try_clone(cpumask)?); + table.cpus = Some(cpus); Ok(table) }