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 3AC2A33ADB2 for ; Wed, 1 Jul 2026 06:05:47 +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=1782885950; cv=none; b=tEGiZ8nP/8y1my2ZCXNL3ziJlP32wewbv5jnwV9lGzftOqI0BtGEV/nTEBH2Zj6aBroRTmWHqSkFPYjRWIyXCyQ+JAk9q42q8gcnU2xEuQyKFZ1asw6hOfs/KbDMzh/9QSLT489/L4uvY3XkPkHLJrQVKM1ucLgjj8Hn9YAT8VA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782885950; c=relaxed/simple; bh=eJfKlRK7k9b2kNcHtsJFOIUyVkQIXxfWWJmLMAk9pP0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N5dqFFNMR1uCvefIvWlCqQS/EpGA/PM01hFWhCRs2n1603n4FfikiRz/afM8Q0egkcxMKl6EC3AvA3I9lZ6Mb0A/AyBWXgBxUQBzk1lLSyUbpJ+k/JOguNRL9MYcVgXjIrzs0JCPSDj0aMsJTZCwGqlB1+f/nXWrxWnlqEl0jT8= 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=OGYpZSjf; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=YXQW4wXh; 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="OGYpZSjf"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="YXQW4wXh" 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 6615lX7j059274 for ; Wed, 1 Jul 2026 06:05:47 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= WYlZ2aPEpqh61K7tMl0TS4HBIg4YZJn9Z3vmihGIy1Y=; b=OGYpZSjfrf7TJ7cE sWtNhxXmpDySRu6KWbyUJzxh5PZhTje+QJwFSIN1nqt+vvhpH6VrSs7ny1UnMfSY qEG6y0Lj5oCHJpJvbaAfVriZ1vSLD07vp3vpf5IFCWqnAL4vcEJkHBHfBCCTimbx j4bnKlNzJuxzJW3zK8Y2RKYqkM14iNF41Igp49gMlDMTCIzIZOsMoPAPXYPHiND9 h30ywhOEd0I2GrLu65N6+nU7PJAN7Cc379OiVDhmbPh1IZzSOdv0XqDzmWto/drl BSYlnkmRvrGYGbe5Dsu3rL8rrRNabIC+xRw5Z1aXAV4edNn32ZgeIbNpslEc+fxK d4cGUA== Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4f4k3sjcde-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 01 Jul 2026 06:05:47 +0000 (GMT) Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-8478e603285so1370746b3a.0 for ; Tue, 30 Jun 2026 23:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1782885947; x=1783490747; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=WYlZ2aPEpqh61K7tMl0TS4HBIg4YZJn9Z3vmihGIy1Y=; b=YXQW4wXhlNDBha49NoL3ZedrpbL+x6P2S4c1DhxQKh+7zahqngs5WVs/ZW1MTgmD2K 76whGdGgsR5aq27ViGWGZywqemaUjnOI7puIBaGqXqOyRUszB/Fz1/Vn05k/AbSxP0Zl K9ERLR7JKrB+cLPTzFd011DFYZ4m/R/RphA0EK9t66+kVGrvdjoMVeUzvRSOYN8TnKmv m5BTXQq+uAUtiZPhM7QLB5YKqu2XTtkkeiFDJA98n9b5OCXeQtI7D/pM/dTGvHjIIzm2 QCXo/Sxn9iKkATys6aFgBQCtdXbUOGoYfl2SY2w2CIoZOE4MRybETAyumndVI0uBkraI ABdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782885947; x=1783490747; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=WYlZ2aPEpqh61K7tMl0TS4HBIg4YZJn9Z3vmihGIy1Y=; b=Sf6rSyFzkF7nLvhRaeIgkfcql7hc6Kc+sygc7l++/j/Wy23VfPBDXoQJhgSF9RMP2X IsKXZ7smCeIlZLqKTF/cRe9e++CP139D0jyhHNkXZ6CvGvaI3BNQ04xzEMLESWoe7gt8 VolH7BeM80jVpN7kJRydLr76SyFJWr2qq87THu/rTFHyu7dOH0//KPtOuHP1vQkC5Ppm kNM1H4pS95X4nXM6yYnQzJnzZa4LNi8KNc5cE423wOzOzy4Cany4thuuZi5nWoeIB5fV FA7IufKPrp8m1bsCUaNG12swBTcTHZpfW5rsI1RLxXyF3Ar0AZBLSr65Ed4DkPLOAOl+ +FQg== X-Forwarded-Encrypted: i=1; AHgh+RoZFr0L7DSorF19Vabr+cBODKwIQz7+KFNuFjqrLbNDLyH2h+6Dioogj1DZ72EfLPppgHGxO7m4rycH1Wc=@vger.kernel.org X-Gm-Message-State: AOJu0Ywe5DbX4WF5/x5SE2jbW/nZGU4DlrbqKO6s+aJ4JpYTIHkYTTNT TKtfrNNQ9GUHYrypRcOcJ4MiJneAWrk/uoXqoT1yVMPO0zDFSG47V/G3ZrybmOFsdeZZzO6KF3o ovIW4wL296UA0R28P0y1dnr69HKL5HDRSrg31KYYN4Bdh7qInCxJzt0jg20b6RWL3TfE= X-Gm-Gg: AfdE7cmLhc6F4zgQG3L7s5ojx8QjNZ98Zavqx+W5CYJUxawGThFNVhbwTKu0e+X/uNW IN4J50F9UgfJZO7j4wnmc/gnXmjeZiYLBBEKFdxVUblbQQJ2GasGqZrmY2kkneN3Kim40AeEs0F hh5uWG7voNvdxxib1iDr/lRlKInp4KGMQW+80gGrptUND/WwQwDZUcAWVrlKvRv/T9pRCt26A3p 9kwoDFBSebMWCy94KuIEhEpAXIvr/V7hf+Uhj1ZnpY4Q9W3BBEQhWe3wWmTj1HCqeCR2dzv7Se1 /wEWCa/tcwmQ0JhC6EKAl3rS7njOE0rp22IizW9B7mb2EcML83AFVkacfpRsxpMLl6qQa/D1F7+ d5oFtQd5mX6XWZFbEzGwC1PcgCTGEaV17Z7oS55O/BujvwCzAgVC8g674HmubPydbOTZAHkXoaQ == X-Received: by 2002:a05:6a00:f8b:b0:847:9223:9726 with SMTP id d2e1a72fcca58-847a82d9976mr3848068b3a.18.1782885946581; Tue, 30 Jun 2026 23:05:46 -0700 (PDT) X-Received: by 2002:a05:6a00:f8b:b0:847:9223:9726 with SMTP id d2e1a72fcca58-847a82d9976mr3848034b3a.18.1782885946032; Tue, 30 Jun 2026 23:05:46 -0700 (PDT) Received: from jiegan-gv.ap.qualcomm.com (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847a02cc6f2sm3317658b3a.30.2026.06.30.23.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2026 23:05:45 -0700 (PDT) From: Jie Gan Date: Wed, 01 Jul 2026 14:05:02 +0800 Subject: [PATCH 1/2] coresight: Fix clock refcount imbalance on platform remove Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260701-fix-clock-refcount-unbalance-v1-1-321dc63c1f90@oss.qualcomm.com> References: <20260701-fix-clock-refcount-unbalance-v1-0-321dc63c1f90@oss.qualcomm.com> In-Reply-To: <20260701-fix-clock-refcount-unbalance-v1-0-321dc63c1f90@oss.qualcomm.com> To: Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , Alexander Shishkin , Anshuman Khandual , Yeoreum Yun , Yuanfang Zhang , Maxime Coquelin , Alexandre Torgue , Tingwei Zhang Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Jie Gan X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1782885936; l=5885; i=jie.gan@oss.qualcomm.com; s=20250909; h=from:subject:message-id; bh=eJfKlRK7k9b2kNcHtsJFOIUyVkQIXxfWWJmLMAk9pP0=; b=Ye3wjloLtfaNwOhrDBxIAdR1lVKRG4RSSV8jrcF2pU1QurgJEaGMXy5PRPwap01Uvx873zQ5h 0XQ5KqPViSnAKt22bDp9kttNW9m3iCQbiK7pRRkqJ5cG0o+oVPQQjaT X-Developer-Key: i=jie.gan@oss.qualcomm.com; a=ed25519; pk=3LxxUZRPCNkvPDlWOvXfJNqNO4SfGdy3eghMb8puHuk= X-Proofpoint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d5pY0jg6k/bd3UW8/tEpCB6x+LCaSr 4Etdbf+V6MWHwbahHwX8wHaGZ3vVZ04= 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-01_01,2026-06-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 spamscore=0 adultscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607010059 coresight_get_enable_clocks() enables the programming clock and the optional AT clock through devm_clk_get_optional_enabled(), which also registers a devm action to call clk_disable_unprepare() when the driver detaches. 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. Resume the device with pm_runtime_get_sync() before pm_runtime_disable() so the clocks are enabled again and balance the devm-managed disable. This affects all CoreSight platform drivers that obtain their clocks through coresight_get_enable_clocks(): catu, cpu-debug, ctcu, etm4x, funnel, replicator, stm, tmc and tpiu. Fixes: 1abc1b212eff ("coresight: Appropriately disable programming clocks") Signed-off-by: Jie Gan --- drivers/hwtracing/coresight/coresight-catu.c | 1 + drivers/hwtracing/coresight/coresight-cpu-debug.c | 1 + drivers/hwtracing/coresight/coresight-ctcu-core.c | 1 + drivers/hwtracing/coresight/coresight-etm4x-core.c | 1 + drivers/hwtracing/coresight/coresight-funnel.c | 1 + drivers/hwtracing/coresight/coresight-replicator.c | 1 + drivers/hwtracing/coresight/coresight-stm.c | 1 + drivers/hwtracing/coresight/coresight-tmc-core.c | 1 + drivers/hwtracing/coresight/coresight-tpiu.c | 1 + 9 files changed, 9 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c index ad8dafea7d2f..f7e501e6cbd7 100644 --- a/drivers/hwtracing/coresight/coresight-catu.c +++ b/drivers/hwtracing/coresight/coresight-catu.c @@ -647,6 +647,7 @@ static void catu_platform_remove(struct platform_device *pdev) return; __catu_remove(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); } diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c b/drivers/hwtracing/coresight/coresight-cpu-debug.c index 3a806c1d50ea..f7efae5b5ce5 100644 --- a/drivers/hwtracing/coresight/coresight-cpu-debug.c +++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c @@ -711,6 +711,7 @@ static void debug_platform_remove(struct platform_device *pdev) return; __debug_remove(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); } diff --git a/drivers/hwtracing/coresight/coresight-ctcu-core.c b/drivers/hwtracing/coresight/coresight-ctcu-core.c index 9043cad42f01..9b6da29d9735 100644 --- a/drivers/hwtracing/coresight/coresight-ctcu-core.c +++ b/drivers/hwtracing/coresight/coresight-ctcu-core.c @@ -266,6 +266,7 @@ static void ctcu_platform_remove(struct platform_device *pdev) return; ctcu_remove(pdev); + pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); } diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 14bb31bd6a0b..147761024c0f 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -2416,6 +2416,7 @@ static void etm4_remove_platform_dev(struct platform_device *pdev) if (drvdata) etm4_remove_dev(drvdata); + pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); } 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); } diff --git a/drivers/hwtracing/coresight/coresight-replicator.c b/drivers/hwtracing/coresight/coresight-replicator.c index 2f382de357ee..2d765f1f73b3 100644 --- a/drivers/hwtracing/coresight/coresight-replicator.c +++ b/drivers/hwtracing/coresight/coresight-replicator.c @@ -313,6 +313,7 @@ static void replicator_platform_remove(struct platform_device *pdev) return; replicator_remove(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); } diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c index 4e860519a73f..a653f1eebeca 100644 --- a/drivers/hwtracing/coresight/coresight-stm.c +++ b/drivers/hwtracing/coresight/coresight-stm.c @@ -1026,6 +1026,7 @@ static void stm_platform_remove(struct platform_device *pdev) return; __stm_remove(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); } diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c index bc5a133ada3e..c9cf486873e2 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-core.c +++ b/drivers/hwtracing/coresight/coresight-tmc-core.c @@ -989,6 +989,7 @@ static void tmc_platform_remove(struct platform_device *pdev) return; __tmc_remove(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); } diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c b/drivers/hwtracing/coresight/coresight-tpiu.c index 7b029d2eb389..72ac93749be1 100644 --- a/drivers/hwtracing/coresight/coresight-tpiu.c +++ b/drivers/hwtracing/coresight/coresight-tpiu.c @@ -286,6 +286,7 @@ static void tpiu_platform_remove(struct platform_device *pdev) return; __tpiu_remove(&pdev->dev); + pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); } -- 2.34.1