From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4183410D32 for ; Mon, 29 Jun 2026 14:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782742689; cv=none; b=V4l/4mYzYsTCAf+qH9oDvZvtETxoV1wfvrwae0i5eZ3iH1DoelE6aP9oEFmXZj1Zy/qLrlNs/BSK5I5aXGujPw89M/aQxHD9nO30odUSYnb63bh0tgaS1sDfvjUoGnVARlu89L9BnA+G+8juv1nze9V4hm3e8BQwzH7MsuwYt54= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782742689; c=relaxed/simple; bh=AcvaTu8lwVofEtagYxqeFhSl9A3VDEnCqUviA/orrDA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fN3L/Z45DNm3H7vvJMmdOHGsRu7TNhFzsfJ/mbMmH63sh57RKUeAy6wi5uapN8wL13qfOE4cNyqfReQJ4RJ5iv/FeMOy2j6N+hcyL0hp5c36AuEIZcXgPsUrpJxHIwqQAuZz3AjWS3oQxRS44wvGrPpRzTrTfdD+Nno+ANj1+Dc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=Kafmva2e; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=SRuTY7mt; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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.b="Kafmva2e"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="SRuTY7mt" Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65TAT69V2641555 for ; Mon, 29 Jun 2026 14:18:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=DbQAzYpcRR5 5NMotjjho3VrXDpNp2yf0yJSS845TzTA=; b=Kafmva2eKXoxaS1lgnJLppUyhD7 IrrL8MYghq8JO1wueUCiosoC/8S4mZ/X0vzT62jD/tytiYWQnSr0p8jvhsAs6e8N 7/MFgXksEFnXFTT8OdAYtuOo7eKQ2sr7S36g77npzE8vV5l/DT15u4syoSM3ySac QOPuxIhh0gSSlmtECxtRQ8Q8uYZIVEIAcFlFRQryeeQBz8X8wkfpyxCb+d4Mt7d3 1pKdyZFKIE0VpD0zQFpPenRQshJVKCJhIzLI9bPbQmX5qKZkMVAKRpQBbKZnuDEM gPhRlx63rpYUBF7ZIn+Hd5TOo+6VljsTsuCpNRvE8DZQscwACxuD7uEQwng== Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4f3n5s1cgr-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 29 Jun 2026 14:18:07 +0000 (GMT) Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-495b4a78694so2586189b6e.0 for ; Mon, 29 Jun 2026 07:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1782742687; x=1783347487; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DbQAzYpcRR55NMotjjho3VrXDpNp2yf0yJSS845TzTA=; b=SRuTY7mt7qCwJ32hcqY4Sj+PrnQ/5Rxe9dGdZ+jjoCyjviyEOGK/ZoC3RxYX8gTzJE YrnYALio+m9msZuELNWQ4y8ISCpQIgUHTqCghPTD/NwToyELsdUfU2/UXA59giCZPxxd /FGWPqUUFXvvHDhDifr8TU/4Wm3WMnTFXUEe+GzaaPKOOxqhrBgTneGm0WRGJ3ASJLNa GZeSYp2eTYGwITvK+/RRJJfT8E40NhY8ZjnoIYNZMx+xn/tgRWnLkWCIO1DQKlUl0+Sh wAhzbvX8QLpbFCv8ToT1m/yMCJmLNg5o5G0lO5q+xrUzlvZkcQ4QDLfChPCR3mdpo2QT 2tzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782742687; x=1783347487; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=DbQAzYpcRR55NMotjjho3VrXDpNp2yf0yJSS845TzTA=; b=Dqd9y/UP3bkIS06kRkV0hOJLHjsD5m3X8Pw8kjn0vvrNslKOz6bAts9N0V9XoPAj1T vkN7WRW2Q5NZJOnDBmdJetOIhsRcyzZiseFKteMcaVgcYmZ1ckcWwoO2wjCk9uqlml3p iItBGvKJryV4ns6Ohv5Wx2+D52+XwPenEUInKPK65vfMhl4ZgyzwoR44pwnKtziCL/RL +8DinSvveQSQEkBeJXMx+esvRNKuhspuasal4BGwZGG0EpPGBW8YsCOHmo3f1E6vEzJj PF9vU8MOfXZs1jyFocAY4QGs6efMpkVd+ij2aVzm3R+KoDVfWy5WDoU0mmlqfc5KbvlV Vkag== X-Forwarded-Encrypted: i=1; AFNElJ91gXpnlThc+pyxGWvqZzmZVrtqkmZUrXzNuSiJmZ9sOXqjAN1gBdKMvngoQeyZqCTT6YTLCkPEcT3mUEE=@vger.kernel.org X-Gm-Message-State: AOJu0YwUtvxUlO3et1n+NiIPfwElD+5VDHGap9Li3mjtqTBrIlS8eK68 jr9Fi+oykOjlj3qK7unQv3J/9yW71bLwdxquIWIlCnsPY9k47e3Cp9NnhNbV9114M+iuQOjraKV w8oDuqDaKoEVF/dS8kAHwESi6A6ZVAgu7i5CQofdI155mUjERdUChIRk+vWDbC8tO9r0= X-Gm-Gg: AfdE7cl/bzRvvK+97YDUtim+xh1HxVjP/0Cr1teIqa97gWBtPUwIcVtkojojUATWRmh Ezt2xlfsJaqUhyZHnlC4jz2eiMt5e/4YlpdaIEjvuV+LUwGIGd5RFKcxhuEtnlHoFWKdvDiifBP 24Khx+lGfQMGguXet8pgfL4Y0NaiCedY+lthNncCMGtrWvQ39rXegrvBpZu6W5kvODmq3pGi58E Q3/ABWKaLzawW/C3awiHSAHs+HZOi0UBbhdfghm6h/rAowPkyzlmPEmQjuRliPAsMXi2MOyjNwh wz1Ll/yltUyecG7pLWq0K2Ae9G+ZPwlci7gbrSznGg/h570YR8s0aKKI3x4c2mXmEihUxnzUqqN bWglv8p2fbUrcJcD31GIUjj2sOSD7xOdoa50Yjg== X-Received: by 2002:a05:6830:4119:b0:7e7:aac:4cc9 with SMTP id 46e09a7af769-7e99bf3fec7mr15081183a34.3.1782742687024; Mon, 29 Jun 2026 07:18:07 -0700 (PDT) X-Received: by 2002:a05:6830:4119:b0:7e7:aac:4cc9 with SMTP id 46e09a7af769-7e99bf3fec7mr15081142a34.3.1782742686417; Mon, 29 Jun 2026 07:18:06 -0700 (PDT) Received: from hu-mojha-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e9e8228746sm647612a34.20.2026.06.29.07.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2026 07:18:06 -0700 (PDT) From: Mukesh Ojha To: Bjorn Andersson , Konrad Dybcio , Bartosz Golaszewski , Guru Das Srinagesh , Sibi Sankar , Elliot Berman , Andrew Halaney Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Mukesh Ojha Subject: [PATCH v2 2/3] firmware: qcom: scm: Fix reserved memory cleanup on probe failure Date: Mon, 29 Jun 2026 19:47:49 +0530 Message-ID: <20260629141750.996853-3-mukesh.ojha@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260629141750.996853-1-mukesh.ojha@oss.qualcomm.com> References: <20260629141750.996853-1-mukesh.ojha@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Info: AW1haW4tMjYwNjI5MDExOSBTYWx0ZWRfXwX8/x+XssR7m 6CnMdZ5s7nnPvHb/H/0lhePNPKuHXYq0izNYl1znms55PLnF9p5M1/OhBHsi4yJdjK8SIqKXONM zALwo0Y4zOt4snhI3LoFJT5VEaXsrsc= X-Proofpoint-ORIG-GUID: ymbnPNNyCcIMgoR6x9zVGA3Ora-gEO7i X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjI5MDExOSBTYWx0ZWRfX3WzgoBkC/62z bed3vCp+Xe+ypcrorY5+VL4ypf8JaRpw8JhaB5T+5AqVXsMjJ6oSsU5AAAWZ8c7MpBhx2ieXUdT uj/yNv+rwegnp3OnUSSsNzDdAc/kzceE0Br05tbgtQ6FSGfAyMURTOjSRu7h6bmWzujKNyC/iWw HxU0dD8fHTG80VjTL+wy2Ng2ZkTn8QFZbMn4cqPcMm0+KtaFov4/UuZdAF0KdJd95xIiB0aJiMu SopeVC7o62YQ1iWq2mDePxb0LtqVWMRhwem3WirVIjdDoqt3YnW420OMKEkvveVG2pc/CII1CRh lcfyo3SNmebrQN+Mn8cZKF69qqZmVDh3drLVxBvEd/GmTxAzm4kCsWOabSrw7LGU5LX609Tv90o B1f7fUrqojJ3b7f3mxgLTnQTC5Sk2ZAMDvPYYQVVKSsb7lKxgzBQd9EYEZj1pdDNXTjotjwFfXt Jq/rWN8UU3+OsMmPnlQ== X-Authority-Analysis: v=2.4 cv=NZzWEWD4 c=1 sm=1 tr=0 ts=6a427e9f cx=c_pps a=WJcna6AvsNCxL/DJwPP1KA==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=mag7UKMDEwzM_1C7KTIA:9 a=_Y9Zt4tPzoBS9L09Snn2:22 X-Proofpoint-GUID: ymbnPNNyCcIMgoR6x9zVGA3Ora-gEO7i X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-29_03,2026-06-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 spamscore=0 adultscore=0 suspectscore=0 clxscore=1015 bulkscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606290119 of_reserved_mem_device_init() adds an entry to a global list with no devres counterpart. If qcom_scm_probe() fails after the call the assignment is never cleaned up. A probe retry would add a duplicate entry, leaking the original one permanently. Add an err_rmem label that calls of_reserved_mem_device_release() and route all error paths after of_reserved_mem_device_init() through it. of_reserved_mem_device_release() is safe to call unconditionally as it simply walks an empty list when nothing was assigned. Fixes: a33b2579c8d3 ("firmware: qcom: scm: add support for SHM bridge memory carveout") Signed-off-by: Mukesh Ojha --- drivers/firmware/qcom/qcom_scm.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 464ae3b4ca43..f0e19fc314b4 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -2785,9 +2785,11 @@ static int qcom_scm_probe(struct platform_device *pdev) "Failed to setup the reserved memory region for TZ mem\n"); ret = qcom_tzmem_enable(scm->dev); - if (ret) - return dev_err_probe(scm->dev, ret, - "Failed to enable the TrustZone memory allocator\n"); + if (ret) { + dev_err_probe(scm->dev, ret, + "Failed to enable the TrustZone memory allocator\n"); + goto err_rmem; + } memset(&pool_config, 0, sizeof(pool_config)); pool_config.initial_size = 0; @@ -2795,9 +2797,12 @@ static int qcom_scm_probe(struct platform_device *pdev) pool_config.max_size = SZ_256K; scm->mempool = devm_qcom_tzmem_pool_new(scm->dev, &pool_config); - if (IS_ERR(scm->mempool)) - return dev_err_probe(scm->dev, PTR_ERR(scm->mempool), - "Failed to create the SCM memory pool\n"); + if (IS_ERR(scm->mempool)) { + ret = PTR_ERR(scm->mempool); + dev_err_probe(scm->dev, ret, + "Failed to create the SCM memory pool\n"); + goto err_rmem; + } ret = qcom_scm_query_waitq_count(scm); scm->wq_cnt = ret < 0 ? QCOM_SCM_DEFAULT_WAITQ_COUNT : ret; @@ -2868,6 +2873,10 @@ static int qcom_scm_probe(struct platform_device *pdev) qcom_scm_gunyah_wdt_init(scm); return 0; + +err_rmem: + of_reserved_mem_device_release(scm->dev); + return ret; } static void qcom_scm_shutdown(struct platform_device *pdev) -- 2.53.0