From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796043962; b=U22bG/5EBbiUZHM8URAOuAdzp/cRTlrJ57svpiNK7qH4MU3JcdjzfrigFijdeF8qFAIc EzbOsEgEbFna55V/LSm2bwg/UkEq93J1KM+9Y7sa6+pGlngaf/ovQM/fT922FIKo9yFQl 7gdEp3FtjsNnT4wRfuBakBl1vPjnpBAYV16zPdJNbTPNbqka3s3Vvjar4CQMhMAF3Vy5Y g6h2Saq0ghmvY+EoyBcrsAUooYGrM7Ms+2XFJX60Q/X2hI90qo2m3IN6zfGprPZSf6eRO SnYu5EnLkQH9qRlhYQ9qTrzO61QyZJ3UKDbY+sOGwZVXjKbYpnAjZd5/28NZFqqToTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796043962; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=lByULrwmCc1lqK5rLuB50tyT1vc/GNhHxrFuokKV6pU=; b=QJ7nRRzphulIztwx4NM4ji6HBg5QC76Mp4Cm8Xh2jIMYsy27XomWrFgCYkDZZe442dbT d3oH/IH+SZ0DjKV7ZWVToZKIGcyHrjVWm30E/1piI17mQITGhiDrRehdsahBmbxTxVcjs 3++g+Up3H8xxWfxnnHGcvhRCk8kCgb1/ygXjNl+GzoEcQA4TErNZkJ8FG0jmuXGbNnWjI i2yMB6+vd/QLcnjuQvgqUCs8zKbDsb7V+cXQ40V0Px4lVQV5/731A0iK9Q5mwqL1WVVYc 8McCjnDK/HeQnkL4O4pvB2m9oValEqQr0ZKLzJu7R1CKxGIABThL2f6zhV3wEJ4Tz3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=fOAWlGL8; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=Xt6u9BT6; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 D5565606A339 for ; Mon, 30 Nov 2026 13:06:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D5565606A339 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=fOAWlGL8; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=Xt6u9BT6 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AU9UsPx1721322 for ; Mon, 30 Nov 2026 13:06:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= lByULrwmCc1lqK5rLuB50tyT1vc/GNhHxrFuokKV6pU=; b=fOAWlGL8JBuCz6Dw gPcNeiQQtCN058TmEdKTH8oKGZ2b+sPyylOLn+RYB23lcQ/IM5pg5kfYHM7wBzza 0g9AqSQn+CtIlzV1mNQlPeqdgnpG2O/y6UaymUnEMr6Pd1AJKjyzd7IzGHLO4cdZ sHtHZnr7dy8vJhtj1MJffa+bcNuIJDFpr6lNbVl9Ni9X8GBbqpgcAuV33UmWvogP gERZnSLQuUupHGDcDIobPn5ytOgDLViSKMm6ajoL7Wsrkh6dAtnPxWeeQpGzUgih 3fBLdBFkgUuirqH6iCPYYK/rlATWAM2RrVArQ3ze371w38/Pj9luxFrVvUHyWNsI ieAoZw== Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j94wfsa54-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 13:06:01 +0000 (GMT) Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-cd66551e02cso9692533a12.2 for ; Mon, 30 Nov 2026 05:06:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796043960; x=1796648760; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=lByULrwmCc1lqK5rLuB50tyT1vc/GNhHxrFuokKV6pU=; b=Xt6u9BT6A+OoATHx2uj+LEaxjNmK8CCBKQ8k2LmiSciQd65Rv29DymRTQzC20owlto yjLIpouTl5egEAOyZ4QBUHNXQL5Wi+8E/0tpTjpNKDxlZ1ecYxgo26+XzgONozPOtirp EUBHmI2kzsLM/XsT+L2c/tcFiJXjDM1s2FSaJlGjZffM/XW1j26f2ymS/bPFW4U28fZp UgjOLjjd5j14CuEovTbsKLwQM0I4wTpEDUQnaH7h09DhIckOl+JZc5qRijX3PeKhB2Zm zBIViiHP29N29JO0IhlxZLL7ScaziHWzC/bVysaLnQpp+4pI3PDiYFKnyj4bNpV6m2qO avmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796043960; x=1796648760; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lByULrwmCc1lqK5rLuB50tyT1vc/GNhHxrFuokKV6pU=; b=rOpUk4itA8EaW0IjJZcOd9ukIYtwH9zlzTq1UwFD7KopybKs/+YyRmhQAFB4INpOmy UYlTqKTHMocxptXelYvfXrW7uwnDWoHVwTZkMMYNt2O9w8+9gyrhXfp1qtVPvc8aZw4z s1lBg1a3+UG49DCwz6mzET5JxyRM+MlUifOR92/bmOWg0XMcCxvZoyRNIPcfhpeTzAFp AD0XuNu7M78mFYBHEoP+Pl+Z8JWe20+N0485wvzUTuLtbVzE22d066eHk3lOXVK3R2Rj DzKg9rkqPSjr4lKrLu+GaWvw2BjXGBoNR6+puiE/zMt+r0hGx25Go8IVhKlwsr9cZJOE SCRA== X-Forwarded-Encrypted: i=1; AL+hErEnlJenyMyecbu4UDPBBj92VK902YHhVjE0oJ2N3fJcCCcCwldzxOtbUpb1MsiDxSmlDqBPeNPJ3BH7MPU=@vger.kernel.org X-Gm-Message-State: APuU4Z9Mvp8TbJc2tCNwFl+GCdp7LS2Nz5OyDOt8O+h9Jz98rA2AE2lw ice+BVvAxejj1FuZtoC7VYPBtG9Lzv+suyC1HLnK4rcxkjUwQvPByTtOkXHS+RpOnTTcxiW0uCc 4ecgdDJosgqBtoW4nlPVKo9DpltSNBonx+sfdFUJ1e5vaxMwMbwOEq9KRNptVkPE4Gaw= X-Gm-Gg: AZFdTZcNkUHwHsv5qrdAnKeEGiuU+uidl07k9pkplrJBMyEd6xQ2pyoYxksaUs/87TX zpxzEaKq44Q8G9+y0Ga6JD2S9RlD8+lCzD4G+g1j9nbcRm8bLzCy5TdL4fwhK+dNg2xJj8RKzas iK8eKtPdHQyZaQ8WKBwtsFzjAcsBv2WyuLnpqL12bvpEIHcNPUYXnYFPGKGP36IhieQqOlnOhj/ Bt0iy/1HtOnDh+lKyAAWTVuZv14XFnrGSoLKKh/gmTihMDeB1dVFJbMxptuY8kbaw0nSw8qNl4a R6G/HbgtVkASdCuJXRkz2XZ0l/bj+f/U5uGgTgV920edp5B33l4emRU/+wB1IYR/2G404OcWVBO nitflCyeaHnYcp+d8Mu+sQ09JpnDlkK8K/dOjGNjAm5au/QQXsVmvNGhrNpLzxSPxGCsvNSjnzg nvtD4BSMbn04RmmyfqFBjEHQHI0BreAidX9UR0l+5HNKGTHw== X-Received: by 2002:a17:90a:e7d0:b0:3a7:3474:b1ee with SMTP id 98e67ed59e1d1-3b41cb3276cmr33284579a91.60.1796043960128; Mon, 30 Nov 2026 05:06:00 -0800 (PST) X-Received: by 2002:a17:90a:e7d0:b0:3a7:3474:b1ee with SMTP id 98e67ed59e1d1-3b41cb3276cmr33284522a91.60.1796043959342; Mon, 30 Nov 2026 05:05:59 -0800 (PST) Received: from [10.133.33.226] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cde6d026d6fsm17881276a12.19.2026.11.30.05.05.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 05:05:58 -0800 (PST) Message-ID: <8c1cd0c9-b854-4516-9915-8d3498d49e47@oss.qualcomm.com> Date: Mon, 30 Nov 2026 21:05:54 +0800 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] rust: opp: clean up OF OPP table on error paths To: Bilal Hashim , Viresh Kumar , Nishanth Menon , Stephen Boyd , Miguel Ojeda Cc: linux-pm@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Zhongqiu Han References: <20261127121129.1150-1-AeeSec@126.com> Content-Language: en-US From: Zhongqiu Han In-Reply-To: <20261127121129.1150-1-AeeSec@126.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDA1MSBTYWx0ZWRfX8qADTtGi9ALT bD5B7L7FXuxf3EARZWz2zV2hkHssg8qGz6iDFrXVqzyOYbNf4xtjHjs5ZqZNdyYDPz2YRkfB8UD HNrOhUDJLzmHzBLGArhTS8h5mdGS3SI= X-Authority-Analysis: v=2.4 cv=BZ1NQbt2 c=1 sm=1 tr=0 ts=6b0d74b9 cx=c_pps a=Oh5Dbbf/trHjhBongsHeRQ==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=gnbuhwpKAAAA:8 a=MokDgb9BjlEwHILOOzwA:9 a=QEXdDO2ut3YA:10 a=_Vgx9l1VpLgwpw_dHYaR:22 a=HL_VsaX-4L8esMsM0cMV:22 X-Proofpoint-ORIG-GUID: VtwdO8EkJRfjO7l-pG3LWvm88y0v1-fN X-Proofpoint-GUID: VtwdO8EkJRfjO7l-pG3LWvm88y0v1-fN X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA1MSBTYWx0ZWRfX8QvjQPmmlrcs 7FrzkZ7HNpA30srjd67p8e2RD9rgmzma7LO20E7xLgsT7whn3HCnF6Z8Ax4+UqdnBYvh1JfJm0B aeC+1HfSOTLMYpyPlTMker6no5zOHx1FWmpUGypm89Yne+3zfFp9MTNVSaIK80p57dhqAJfvIB1 25goon4AZrhO20+zzuMwN0ptlflRnGHFAI/WrHomv0po8PMkrxN6nWFdKlzwX9paryZjG2SmG4d +tTY1zV4u+OOecULI7Qr+nyQXlTx4iEqqE7aCpHmxo23iNVFPZJ9QAcbqjyNWSGwKCQis49JqFm EewEF9qLNBvNFfucNQhF3xL/DKmFcjQF1kIIRYf7ItvQwhGOZBwzjsoIW+j/0q5TfJN7uZSFH8Q /ExpkWMh1XZPeE13MFK5UEyeFUAnosTM+fEiAmr7KmEMTwUn9cGE5A6DjgmUCwADpZHtMZzazUg oc8MaMZxuA2/19ew8Tg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-30_03,2026-11-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 phishscore=0 bulkscore=0 malwarescore=0 impostorscore=0 clxscore=1015 spamscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300051 On 11/27/2026 8:11 PM, Bilal Hashim wrote: > In Table::from_of(), if Self::from_dev(dev) fails after > dev_pm_opp_of_add_table_indexed() has succeeded, the newly added C-side > OF OPP table is leaked because Table is never constructed and Drop does > not run. > > Similarly, in Table::from_of_cpumask(), if either Self::from_dev(dev) or > CpumaskVar::try_clone(cpumask) fails after > dev_pm_opp_of_cpumask_add_table() succeeds, the C-side cpumask OPP table > is leaked. > > Fix both paths by rolling back dev_pm_opp_of_remove_table() / > dev_pm_opp_of_cpumask_remove_table() when Self::from_dev(dev) fails, and > by cloning the cpumask before calling dev_pm_opp_of_cpumask_add_table(). > > Signed-off-by: Bilal Hashim > --- > --- a/rust/kernel/opp.rs > +++ b/rust/kernel/opp.rs > @@ -667,7 +667,14 @@ impl Table { > to_result(unsafe { bindings::dev_pm_opp_of_add_table_indexed(dev.as_raw(), index) })?; > > // Get the newly created [`Table`]. > - let mut table = Self::from_dev(dev)?; > + let mut table = match Self::from_dev(dev) { > + Ok(table) => table, > + Err(e) => { > + // SAFETY: `dev` is valid and we just added the OF OPP table above. > + unsafe { bindings::dev_pm_opp_of_remove_table(dev.as_raw()) }; > + return Err(e); > + } > + }; This rollback is unreachable/ a no-op. Once dev_pm_opp_of_add_table_indexed() succeeds, dev is already on the table's dev_list. dev_list entries are only removed in _opp_table_kref_release(), so from_dev() cannot fail here. Even if it did fail, dev_pm_opp_of_remove_table(dev) would repeat the same _find_opp_table(dev) lookup. It would get -ENODEV and return without doing anything. Please drop this hunk. > table.of = true; > > Ok(table) > @@ -689,14 +696,23 @@ impl Table { > 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. > // > // INVARIANT: The reference-count is incremented by the C code and is decremented when > // [`Table`] goes out of scope. > to_result(unsafe { bindings::dev_pm_opp_of_cpumask_add_table(cpumask.as_raw()) })?; > > // Fetch the newly created table. > - let mut table = Self::from_dev(dev)?; > - table.cpus = Some(CpumaskVar::try_clone(cpumask)?); > + let mut table = match Self::from_dev(dev) { > + Ok(table) => table, > + Err(e) => { > + // SAFETY: The cpumask is valid and we just added the OF OPP table above. > + unsafe { bindings::dev_pm_opp_of_cpumask_remove_table(cpumask.as_raw()) }; This is only reached if dev is not one of the CPUs in cpumask. The only in-tree user, rcpufreq_dt, derives dev and the mask from the same policy CPU, so from_dev() cannot fail there, for the same reason as in from_of() above. Should we consider dropping it as well? > + return Err(e); > + } > + }; > + table.cpus = Some(cpus); > > Ok(table) > } > Please keep only the clone change, update the commit message accordingly, and add a Fixes: tag. > -- Thx and BRs, Zhongqiu Han