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 69B102D7DF1 for ; Thu, 2 Jul 2026 01:56:13 +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=1782957376; cv=none; b=Q/RnIjZHwtxAldEhIhJ1gk6EOWv9yUuAj9TsDGrSeuVqNj3JLycsuty8hOT5wk0kUoO21SYMZJf+mxaJo+VqoPJYpNOOp+1MY0D0bjuLh3lTag5fF/1WHbdVT+sTZZhWabvxGlh6taB7OCLDeyZRL3gBhqE6UgGyif06AouZ4T8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782957376; c=relaxed/simple; bh=rbaZjPhDTSox7LtWsmcCphF9LUcOcfMcQxQKBTvDGV0=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=dFxWR2stZY90jue2aG0FHFnvgz9OUB7VcCyeYLwqWNDeXEBvgwBd80aUVq7YopssmZomjtyKJpN7IIJh6qkn9gly24O2lUQpL4BoXCwWCnz7hH9P9swbNOd0secM3tSZmQnT47F6V2T0lVkHDPxbyFR8SZwnHLFXywqWJqrPtac= 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=U8S8x3i+; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=IiDx1gy6; 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="U8S8x3i+"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="IiDx1gy6" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6621Khrv2917728 for ; Thu, 2 Jul 2026 01:56:12 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= LTWT9sxhpyXcjkqFehsCH+/HBJQR/dfUs1L9UJNd16c=; b=U8S8x3i+7rLUqeZ2 fcYGN7jlpBH43ZIl62Oabjx2cKNzdogm2KVS1A/ejwPaYqnyG77UTQ4b5jY4gUlz kU8bfzFOO69nQbo4KZz/V+s9nk66ev+4ShSwP1zGx84gtQt1FQrCk3HCLewBIgnM VXe40fPPFnIf/zg64zo6gMaeBqqmxOYw2Fz3Ip68zAh1jmdsuZujStqIPYN2gGeq gb7RwdSTDp5Odw9hIYknk1Y0ORgKN52ff+O3mHl0r/hRfFILKXMdZvxJ1WJbO7uH lHK//YfP95Y4EMEwo1q8KeMDRRn9Q9RHKJKKuGjK6VR3NXcIR3EBOweMjMI1o/si BfFydw== Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4f53q0an40-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 02 Jul 2026 01:56:12 +0000 (GMT) Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-c88d7a75507so1687092a12.1 for ; Wed, 01 Jul 2026 18:56:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1782957372; x=1783562172; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=LTWT9sxhpyXcjkqFehsCH+/HBJQR/dfUs1L9UJNd16c=; b=IiDx1gy6g+zFqttu++Zz4VYObwisJhS6V+QbiT9oawo0CcYV1NK5szQxaWDyJifjeE t3chQ+qhflyjOWbQDmvdsveMLxsfTxLbIzmMQKQ3n1/03oUHVtYbf5HnPU0T5TkkeosZ j3DTBMg21PeOVWpYVVe3qxP7UW9EGCFinFoqKoY6CZIqi4sXxb0by03Kj1uaDf4wITOd JhJZKMP+S7SnaVMcx/g24wuOH1oEhHP2qdeUqFEonyAoxLRJGPmx+pGY8DPfDVMeCE4g aXXQp3oqyFIzal0VZXoscFqOkNVcbfqHZBHqOLR6Ka9CxRTiFDGgK+os9yr6M0fnHB4j S3GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782957372; x=1783562172; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LTWT9sxhpyXcjkqFehsCH+/HBJQR/dfUs1L9UJNd16c=; b=Hm0tFMkS5KbYge2/LKgI+Abdd2Y+wpnX9IbnX4O/X6R4zUdYfpLzLzr/uORXeZDSuz 04EVxsB0Qa3gTpE51zWTcZPafNkOqNX5DN0FuyWTzQcbkzhxOLbIvnRNY/d60rw1bUOM /ZcOz2VCTIu5jM1fjUhL1wHEXlbCgBcxIFCQ0H6AXc0gW8HEY3Vzn0fyY2oRlCvh+/PM Gc0idVGPOzF1Q80otTELtv8VGkRdjS4Pi4RtW3wWnpLH+nzBsz21O1L+Q/ME48hZgtIl J3m3jZVbZmU6B9ZkScZp4P6GPqCZGCJhMOM60Gg9H+EvNc6Hl43DSpw1+DX6PS/T26wP N7tg== X-Forwarded-Encrypted: i=1; AHgh+Ro/VlEqUez5YGufGxybUTIDME/X9yRH6k6Y+ht+Vf8QCKeC2ysLjoM326zNiRQnGa0aN7AbGsW2asCR1jE=@vger.kernel.org X-Gm-Message-State: AOJu0YxxI/TVxe/fTAtMByMUrBUB+gngZPlUxRJ6PHmuw2EKhSUAsp9i D3lGOzd5/0e6SGiidSHsB86aPUskrTmxmySa6S7VfJOhSg2OB/p/Pm3kagg1g22DLmuE48ctbVP Bv9sdHWC6PLi00J/q+uaXFXgG/8RxYKu14oecLbdsjw9O9/JFobbyIBgHgRyFvGaHWS4= X-Gm-Gg: AfdE7cmAuaduAz/w1kj1Z/odPUSbfyp0p4A9XH3ITjiAfeRoADjtuKO3LIsJ72mwcJs YzN2/mFcpsB3AT6e/V5b+NNHu8Wm9CHvC1v7PY2uCnVPZ5LnClYijy6SxO7rgyx3W6LDR6uh14I Q0g3bKEyOd0zYcY16jH+shJbg8/eE2Y26+bAfhznRFBAO+0zJ1N89LE3aYll8eKMGctecXYcbjF Pcrag1raCksW7vw5dyaOWjgi8lHZ3OQkZOmXpu8PtMISLIpyVF6JwbcJ0GwqclZ3SZXHitDzaxW y+9Ija9Act7g1afWTX9lWBiCiOXtiPMcrHERrgaSfgSys/cHC7BUMbxnYSQJg9WXqPiqnlGWILT Ho3JLk9ktIXPHtgJqLSkVAqjV1BA2EH+Yo3+954KYgUrTHp6hhoIq/UtsAGuEb6SEcKkeJhg8NU 44 X-Received: by 2002:a05:6a00:982:b0:847:9585:73bc with SMTP id d2e1a72fcca58-847c0673ea7mr3875198b3a.1.1782957371530; Wed, 01 Jul 2026 18:56:11 -0700 (PDT) X-Received: by 2002:a05:6a00:982:b0:847:9585:73bc with SMTP id d2e1a72fcca58-847c0673ea7mr3875162b3a.1.1782957370821; Wed, 01 Jul 2026 18:56:10 -0700 (PDT) Received: from [10.133.33.125] (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847cb6dc4d0sm567315b3a.3.2026.07.01.18.56.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Jul 2026 18:56:10 -0700 (PDT) Message-ID: <4e41e58e-5fbf-4564-bf9e-cec42570f3d5@oss.qualcomm.com> Date: Thu, 2 Jul 2026 09:56:05 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] coresight: Fix clock refcount imbalance on platform remove From: Jie Gan To: Leo Yan Cc: Suzuki K Poulose , Mike Leach , James Clark , Alexander Shishkin , Anshuman Khandual , Yeoreum Yun , Yuanfang Zhang , Maxime Coquelin , Alexandre Torgue , Tingwei Zhang , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com References: <20260701-fix-clock-refcount-unbalance-v1-0-321dc63c1f90@oss.qualcomm.com> <20260701-fix-clock-refcount-unbalance-v1-1-321dc63c1f90@oss.qualcomm.com> <20260701162321.GG1812158@e132581.arm.com> <5218878b-c91f-4d14-ba12-68edf7b3f4a7@oss.qualcomm.com> Content-Language: en-US In-Reply-To: <5218878b-c91f-4d14-ba12-68edf7b3f4a7@oss.qualcomm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Authority-Analysis: v=2.4 cv=dtnrzVg4 c=1 sm=1 tr=0 ts=6a45c53c cx=c_pps a=oF/VQ+ItUULfLr/lQ2/icg==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=P5EO7plK2hrSIlTIuPsA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=3WC7DwWrALyhR5TkjVHa:22 X-Proofpoint-ORIG-GUID: yhoylrSh6DWiz4n3W08IqNfHxlDKJAR6 X-Proofpoint-GUID: yhoylrSh6DWiz4n3W08IqNfHxlDKJAR6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzAyMDAxNyBTYWx0ZWRfX6O8E4yViDtFa Cq7oAGcF4OPe/h/+biOXIP/vDRi8vZetSv0jBd2ws5ZOgQzwqAyzdigZBmUaEAesMd8PzFpWiZN FyaMii1JmgiYtQ3Sk1x6sGdw3nrxo7Q/datO4x1aWFGXiTscKuvS+OFyRhuFKXw3P0a+M74ajLZ tK+tolxHOgCgf2Or1SiLb8sDO9NsQfbVfywfJFtDZAgzqIadTo+VuXF2VeYTLfEIBFR50PzbQZn 0vIz9vJizf/oyeueM+6jBARTuFWP5ZFOF2H9cxJeJ5CmAyG5JVfP3ivJ/SrKCuYOcWJtgM2TW5w /LYSuWe3+q5juzFjP2EoBEpeUaAskL6FOrH0bcpAKvlIlmaWzqfVJr72ecXYZlOHFjUJ4wGzE61 8KQ+MbtMeOkAEGdmsI3d/kdpPULP11Qi0Qe2WPUwQ7MY5vAmGSP/4cBB6hxW1EqC/S7vbeKZaTQ YMvkNx+0eTNKcLHeoTg== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzAyMDAxNyBTYWx0ZWRfX/9KH0Xkp7nTd F02NghgEixSlt8rRCUHIYsUxuq5LehP6YMa0pDaoX30BtWHENlMvVuPTtU0mpJB4TWDYudat6dk eQXcfMbYfuliJQkmI/y5vpJwYzYovzc= 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-07-02_01,2026-06-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 priorityscore=1501 suspectscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 bulkscore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607020017 Hi Leo, On 7/2/2026 8:59 AM, Jie Gan wrote: > Hi Leo, > > On 7/2/2026 12:23 AM, Leo Yan wrote: >> On Wed, Jul 01, 2026 at 02:05:02PM +0800, Jie Gan wrote: >> >>> After probe, pm_runtime_put() allows the device to suspend and the >>> runtime suspend callback disables the same clocks. During remove the >>> device is left runtime suspended, so pm_runtime_disable() freezes it >>> with the clocks already disabled. The devm cleanup that runs afterwards >>> calls clk_disable_unprepare() a second time, underflowing the clock >>> enable refcount. >> >> Thanks for fixing the issue. >> >> The problem is that if the device has already been runtime suspended and >> its clock has been disabled, afterwards when remove the device, the devm >> cleanup disables the clock again, resulting in clock count underflow. >> >>> diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/ >>> drivers/hwtracing/coresight/coresight-funnel.c >>> index 0abc11f0690c..4c5b94640e6a 100644 >>> --- a/drivers/hwtracing/coresight/coresight-funnel.c >>> +++ b/drivers/hwtracing/coresight/coresight-funnel.c >>> @@ -334,6 +334,7 @@ static void funnel_platform_remove(struct >>> platform_device *pdev) >>>           return; >>>       funnel_remove(&pdev->dev); >>> +    pm_runtime_get_sync(&pdev->dev); >>>       pm_runtime_disable(&pdev->dev); >> >> Let's use the funnel driver for the discussion. Once we agree on the >> approach, we can apply the same change to the other CoreSight platform >> drivers. >> >> How about the following teardown? >> >>   static void funnel_platform_remove(struct platform_device *pdev) >>   { >>          struct funnel_drvdata *drvdata = dev_get_drvdata(&pdev->dev); >> +       int ret; >> >>          if (WARN_ON(!drvdata)) >>                  return; >> >> +       ret = pm_runtime_get_sync(&pdev->dev); >> +       if (ret < 0) >> +               dev_warn(&pdev->dev, "failed to resume before remove: >> %d\n", ret); >> + >>          funnel_remove(&pdev->dev); >> + >>          pm_runtime_disable(&pdev->dev); >> +       pm_runtime_set_suspended(&pdev->dev); >> +       pm_runtime_put_noidle(&pdev->dev); >>   } > > This proposal looks good to me. I forgot to add pm_runtime_put_noidle to > drop the useless reference which created by pm_runtime_get_sync. > I dropped the line to check the return value for simplifying. Here is the final version from my part, can you please help to review again? static void funnel_platform_remove(struct platform_device *pdev) { struct funnel_drvdata *drvdata = dev_get_drvdata(&pdev->dev); if (WARN_ON(!drvdata)) return; - funnel_remove(&pdev->dev); + /* + * Resume the device so its clocks are enabled again, balancing the + * clk_disable_unprepare() that devm runs when the driver detaches. + * Then mark it suspended and drop the usage count taken here. + */ pm_runtime_get_sync(&pdev->dev); + funnel_remove(&pdev->dev); pm_runtime_disable(&pdev->dev); + pm_runtime_set_suspended(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); } Thanks, Jie > Thanks, > Jie > >> >> The idea is to first resume the device with pm_runtime_get_sync(), then >> perform the remove (which is safe if they need to access or clean up >> hardware state), and finally clean up the runtime PM states. I mainly >> referred to drivers/iio/adc/stm32-adc.c. >> >> Thanks, >> Leo >