* [PATCH] coresight: Fix clock refcount imbalance on platform probe failure
@ 2026-09-07 6:03 Jie Gan
2026-09-09 9:28 ` Leo Yan
0 siblings, 1 reply; 3+ messages in thread
From: Jie Gan @ 2026-09-07 6:03 UTC (permalink / raw)
To: Suzuki K Poulose, Mike Leach, James Clark, Leo Yan,
Alexander Shishkin, Maxime Coquelin, Alexandre Torgue,
Yeoreum Yun, Tingwei Zhang
Cc: coresight, linux-arm-kernel, linux-kernel, linux-stm32, Jie Gan
Each CoreSight platform_driver's probe() enables its clocks via
coresight_get_enable_clocks() -> devm_clk_get_optional_enabled(), which
registers a devm cleanup to run clk_disable_unprepare() on driver
detach. The probe wrapper then unconditionally calls pm_runtime_put()
regardless of whether the inner probe succeeded, so on failure this
also fires runtime_suspend() and disables the same clocks a first
time. The driver core then unwinds the failed probe and runs the devm
cleanup, disabling them a second time and underflowing the refcount:
coresight-etm4x etm0: probe with driver coresight-etm4x failed with error -22
------------[ cut here ]------------
qdss_clk already disabled
WARNING: CPU: 1 PID: 432 at drivers/clk/clk.c:1188 clk_core_disable+0x1d0/0x218
...
------------[ cut here ]------------
Unpreparing enabled qdss_clk
WARNING: CPU: 0 PID: 432 at drivers/clk/clk.c:1061 clk_core_unprepare+0x248/0x268
...
qdss_clk is shared by every CoreSight node, so the extra disable drives
its refcount to 0 while sibling devices still expect it enabled. The
next funnel to probe then touches unclocked hardware and panics:
SError Interrupt on CPU1, code 0x00000000be000000 -- SError
Kernel panic - not syncing: Asynchronous SError Interrupt
...
coresight_clear_self_claim_tag+0x7c/0x1e0 [coresight] (P)
funnel_probe+0x114/0x2e0 [coresight_funnel]
dynamic_funnel_probe+0x24/0x70 [coresight_funnel]
Use pm_runtime_put_noidle() instead of pm_runtime_put() on the failure
path so it drops the usage count without invoking runtime_suspend(),
leaving the devm cleanup as the sole disabler.
Affects catu, ctcu, etm4x, funnel, replicator, stm, tmc, tpiu and tnoc,
all of which share this probe skeleton.
Fixes: 1abc1b212eff ("coresight: Appropriately disable programming clocks")
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
drivers/hwtracing/coresight/coresight-catu.c | 9 ++++++---
drivers/hwtracing/coresight/coresight-ctcu-core.c | 9 ++++++---
drivers/hwtracing/coresight/coresight-etm4x-core.c | 10 ++++++----
drivers/hwtracing/coresight/coresight-funnel.c | 9 ++++++---
drivers/hwtracing/coresight/coresight-replicator.c | 9 ++++++---
drivers/hwtracing/coresight/coresight-stm.c | 9 ++++++---
drivers/hwtracing/coresight/coresight-tmc-core.c | 9 ++++++---
drivers/hwtracing/coresight/coresight-tnoc.c | 9 ++++++---
drivers/hwtracing/coresight/coresight-tpiu.c | 9 ++++++---
9 files changed, 54 insertions(+), 28 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-catu.c b/drivers/hwtracing/coresight/coresight-catu.c
index ad8dafea7d2f..9a59a1f9e7fd 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -632,11 +632,14 @@ static int catu_platform_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
ret = __catu_probe(&pdev->dev, res);
- pm_runtime_put(&pdev->dev);
- if (ret)
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
- return ret;
+ pm_runtime_put(&pdev->dev);
+ return 0;
}
static void catu_platform_remove(struct platform_device *pdev)
diff --git a/drivers/hwtracing/coresight/coresight-ctcu-core.c b/drivers/hwtracing/coresight/coresight-ctcu-core.c
index 9043cad42f01..ab0232537523 100644
--- a/drivers/hwtracing/coresight/coresight-ctcu-core.c
+++ b/drivers/hwtracing/coresight/coresight-ctcu-core.c
@@ -251,11 +251,14 @@ static int ctcu_platform_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
ret = ctcu_probe(pdev);
- pm_runtime_put(&pdev->dev);
- if (ret)
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
- return ret;
+ pm_runtime_put(&pdev->dev);
+ return 0;
}
static void ctcu_platform_remove(struct platform_device *pdev)
diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
index 2247ad55d444..ed102f6203be 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -2330,12 +2330,14 @@ static int etm4_probe_platform_dev(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
ret = etm4_probe(&pdev->dev);
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
+ pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
pm_runtime_put(&pdev->dev);
- if (ret)
- pm_runtime_disable(&pdev->dev);
-
- return ret;
+ return 0;
}
static int etm4_probe_cpu(unsigned int cpu)
diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/drivers/hwtracing/coresight/coresight-funnel.c
index 0abc11f0690c..d75f11fda72f 100644
--- a/drivers/hwtracing/coresight/coresight-funnel.c
+++ b/drivers/hwtracing/coresight/coresight-funnel.c
@@ -319,11 +319,14 @@ static int funnel_platform_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
ret = funnel_probe(&pdev->dev, res);
- pm_runtime_put(&pdev->dev);
- if (ret)
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
- return ret;
+ pm_runtime_put(&pdev->dev);
+ return 0;
}
static void funnel_platform_remove(struct platform_device *pdev)
diff --git a/drivers/hwtracing/coresight/coresight-replicator.c b/drivers/hwtracing/coresight/coresight-replicator.c
index 2f382de357ee..3fe5eb5a7a0c 100644
--- a/drivers/hwtracing/coresight/coresight-replicator.c
+++ b/drivers/hwtracing/coresight/coresight-replicator.c
@@ -298,11 +298,14 @@ static int replicator_platform_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
ret = replicator_probe(&pdev->dev, res);
- pm_runtime_put(&pdev->dev);
- if (ret)
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
- return ret;
+ pm_runtime_put(&pdev->dev);
+ return 0;
}
static void replicator_platform_remove(struct platform_device *pdev)
diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c
index 4e860519a73f..5de0adf1d33a 100644
--- a/drivers/hwtracing/coresight/coresight-stm.c
+++ b/drivers/hwtracing/coresight/coresight-stm.c
@@ -1011,11 +1011,14 @@ static int stm_platform_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
ret = __stm_probe(&pdev->dev, res);
- pm_runtime_put(&pdev->dev);
- if (ret)
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
- return ret;
+ pm_runtime_put(&pdev->dev);
+ return 0;
}
static void stm_platform_remove(struct platform_device *pdev)
diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
index bc5a133ada3e..2481bae5c9f3 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-core.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -974,11 +974,14 @@ static int tmc_platform_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
ret = __tmc_probe(&pdev->dev, res);
- pm_runtime_put(&pdev->dev);
- if (ret)
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
- return ret;
+ pm_runtime_put(&pdev->dev);
+ return 0;
}
static void tmc_platform_remove(struct platform_device *pdev)
diff --git a/drivers/hwtracing/coresight/coresight-tnoc.c b/drivers/hwtracing/coresight/coresight-tnoc.c
index 9e8de4323d28..d06731c45a1a 100644
--- a/drivers/hwtracing/coresight/coresight-tnoc.c
+++ b/drivers/hwtracing/coresight/coresight-tnoc.c
@@ -288,11 +288,14 @@ static int itnoc_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
ret = _tnoc_probe(&pdev->dev, res);
- pm_runtime_put(&pdev->dev);
- if (ret)
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
- return ret;
+ pm_runtime_put(&pdev->dev);
+ return 0;
}
static void itnoc_remove(struct platform_device *pdev)
diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c b/drivers/hwtracing/coresight/coresight-tpiu.c
index 7b029d2eb389..9ae94dc553d7 100644
--- a/drivers/hwtracing/coresight/coresight-tpiu.c
+++ b/drivers/hwtracing/coresight/coresight-tpiu.c
@@ -271,11 +271,14 @@ static int tpiu_platform_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev);
ret = __tpiu_probe(&pdev->dev, res);
- pm_runtime_put(&pdev->dev);
- if (ret)
+ if (ret) {
+ pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ return ret;
+ }
- return ret;
+ pm_runtime_put(&pdev->dev);
+ return 0;
}
static void tpiu_platform_remove(struct platform_device *pdev)
---
base-commit: af5f12805e5cefa4fe68d6127c7e1fb78cd5535c
change-id: 20260907-fix-clk-issue-51e43c533250
Best regards,
--
Jie Gan <jie.gan@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] coresight: Fix clock refcount imbalance on platform probe failure
2026-09-07 6:03 [PATCH] coresight: Fix clock refcount imbalance on platform probe failure Jie Gan
@ 2026-09-09 9:28 ` Leo Yan
2026-09-09 12:28 ` Jie Gan
0 siblings, 1 reply; 3+ messages in thread
From: Leo Yan @ 2026-09-09 9:28 UTC (permalink / raw)
To: Jie Gan
Cc: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Yeoreum Yun, Tingwei Zhang,
coresight, linux-arm-kernel, linux-kernel, linux-stm32
Hi Jie,
Thanks for fixing! It is shame that my single patch caused issues both
in driver's probe and remove - I have to admit that I don't understand
runtime PM's state machine.
TBC, this patch only fixes probe. The driver's remove is fixed in:
https://lore.kernel.org/linux-arm-kernel/20260710-fix-clock-refcount-unbalance-v3-0-a37a1fb17981@oss.qualcomm.com/
The series above and this patch should be picked up together so can
have complete fix.
> The probe wrapper then unconditionally calls pm_runtime_put()
> regardless of whether the inner probe succeeded, so on failure this
> also fires runtime_suspend() and disables the same clocks a first
> time.
pm_runtime_put() can be used for success case, but for the failure
case, we should disable the runtime PM but not release reference:
https://docs.kernel.org/power/runtime_pm.html#runtime-pm-initialization-device-probing-and-removal
> @@ -632,11 +632,14 @@ static int catu_platform_probe(struct platform_device *pdev)
> pm_runtime_enable(&pdev->dev);
>
> ret = __catu_probe(&pdev->dev, res);
> - pm_runtime_put(&pdev->dev);
> - if (ret)
> + if (ret) {
> + pm_runtime_put_noidle(&pdev->dev);
> pm_runtime_disable(&pdev->dev);
Nitpick: please reverse the sequence between pm_runtime_put_noidle()
and pm_runtime_disable(). As we need to first disable runtime PM for
the device, then release usage reference.
Since the driver core will reset device's active state, AI told me that
calling pm_runtime_set_suspended() is redundant. It is still good to
explicitly call it for bookkeeping. This can be aligned with the change
in driver remove.
Thus, please update the flow:
pm_runtime_disable(&pdev->dev);
pm_runtime_set_suspended(dev);
pm_runtime_put_noidle(&pdev->dev);
With the update:
Reviewed-by: Leo Yan <leo.yan@arm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] coresight: Fix clock refcount imbalance on platform probe failure
2026-09-09 9:28 ` Leo Yan
@ 2026-09-09 12:28 ` Jie Gan
0 siblings, 0 replies; 3+ messages in thread
From: Jie Gan @ 2026-09-09 12:28 UTC (permalink / raw)
To: Leo Yan
Cc: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
Maxime Coquelin, Alexandre Torgue, Yeoreum Yun, Tingwei Zhang,
coresight, linux-arm-kernel, linux-kernel, linux-stm32
On 9/9/2026 5:28 PM, Leo Yan wrote:
Hi Leo,
> Hi Jie,
>
> Thanks for fixing! It is shame that my single patch caused issues both
> in driver's probe and remove - I have to admit that I don't understand
> runtime PM's state machine.
>
> TBC, this patch only fixes probe. The driver's remove is fixed in:
> https://lore.kernel.org/linux-arm-kernel/20260710-fix-clock-refcount-unbalance-v3-0-a37a1fb17981@oss.qualcomm.com/
>
> The series above and this patch should be picked up together so can
> have complete fix.
>
>> The probe wrapper then unconditionally calls pm_runtime_put()
>> regardless of whether the inner probe succeeded, so on failure this
>> also fires runtime_suspend() and disables the same clocks a first
>> time.
>
> pm_runtime_put() can be used for success case, but for the failure
> case, we should disable the runtime PM but not release reference:
> https://docs.kernel.org/power/runtime_pm.html#runtime-pm-initialization-device-probing-and-removal
>
>> @@ -632,11 +632,14 @@ static int catu_platform_probe(struct platform_device *pdev)
>> pm_runtime_enable(&pdev->dev);
>>
>> ret = __catu_probe(&pdev->dev, res);
>> - pm_runtime_put(&pdev->dev);
>> - if (ret)
>> + if (ret) {
>> + pm_runtime_put_noidle(&pdev->dev);
>> pm_runtime_disable(&pdev->dev);
>
> Nitpick: please reverse the sequence between pm_runtime_put_noidle()
> and pm_runtime_disable(). As we need to first disable runtime PM for
> the device, then release usage reference.
>
> Since the driver core will reset device's active state, AI told me that
> calling pm_runtime_set_suspended() is redundant. It is still good to
> explicitly call it for bookkeeping. This can be aligned with the change
> in driver remove.
>
> Thus, please update the flow:
>
> pm_runtime_disable(&pdev->dev);
> pm_runtime_set_suspended(dev);
> pm_runtime_put_noidle(&pdev->dev);
>
> With the update:
will update the flow in next version.
Thanks for reviewing.
Jie
>
> Reviewed-by: Leo Yan <leo.yan@arm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-09 12:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-07 6:03 [PATCH] coresight: Fix clock refcount imbalance on platform probe failure Jie Gan
2026-09-09 9:28 ` Leo Yan
2026-09-09 12:28 ` Jie Gan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®