* [PATCH v3 0/3] coresight: Fix fwnode reference leaks on probe failure
@ 2026-12-02 10:09 Yige Jiang
2026-12-02 10:09 ` [PATCH v3 1/3] coresight: tpdm: Fix fwnode reference leak " Yige Jiang
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Yige Jiang @ 2026-12-02 10:09 UTC (permalink / raw)
To: Suzuki K Poulose, Alexander Shishkin
Cc: Yige Jiang, Mike Leach, James Clark, Leo Yan, coresight,
linux-arm-kernel, linux-kernel
The CoreSight core releases the destination fwnode references acquired
during platform data lookup when registration fails or the device is
unregistered. Move the lookups in TPDM, TNOC and TPDA after the other
probe steps that can fail. TNOC and TPDA also return the trace IDs they
allocated if lookup or registration fails.
Changes in v3:
- Group the three patches in one thread following James Clark's feedback.
No code changes from v2.
- Review: https://lore.kernel.org/r/b83bfb3d-d654-4b99-8ed5-ddbbf90fa6e1@linaro.org
- v2 was posted as three separate threads:
https://lore.kernel.org/r/20261126-coresight-v2-58e559131f2f@gmail.com
https://lore.kernel.org/r/20261126-coresight-v2-9e483a5f35a7@gmail.com
https://lore.kernel.org/r/20261126-coresight-v2-e1077abdea61@gmail.com
Changes in v2:
- Rebase the TPDM fix on the CoreSight next tree.
- Add separate TNOC and TPDA fixes following the review of v1.
- v1: https://lore.kernel.org/all/rc-b1-20261110-vc-178-2d9055f946c8@gmail.com/
Testing on the v2 code: the baseline and patched TPDM, TNOC and TPDA
objects built on arm64 with GCC 14.2.0 and W=1, without warnings.
No hardware or runtime tests were performed.
Yige Jiang (3):
coresight: tpdm: Fix fwnode reference leak on probe failure
coresight: tnoc: Fix fwnode reference leak on probe failure
coresight: tpda: Fix fwnode reference leak on probe failure
drivers/hwtracing/coresight/coresight-tnoc.c | 22 +++++++++++++--------
drivers/hwtracing/coresight/coresight-tpda.c | 29 ++++++++++++++++++----------
drivers/hwtracing/coresight/coresight-tpdm.c | 11 ++++++-----
3 files changed, 39 insertions(+), 23 deletions(-)
base-commit: b7d7462c7f973b65de511db6bebb99fb29946ed8
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 1/3] coresight: tpdm: Fix fwnode reference leak on probe failure
2026-12-02 10:09 [PATCH v3 0/3] coresight: Fix fwnode reference leaks on probe failure Yige Jiang
@ 2026-12-02 10:09 ` Yige Jiang
2026-12-02 10:09 ` [PATCH v3 2/3] coresight: tnoc: " Yige Jiang
2026-12-02 10:09 ` [PATCH v3 3/3] coresight: tpda: " Yige Jiang
2 siblings, 0 replies; 4+ messages in thread
From: Yige Jiang @ 2026-12-02 10:09 UTC (permalink / raw)
To: Suzuki K Poulose, Alexander Shishkin
Cc: Yige Jiang, Mike Leach, James Clark, Leo Yan, coresight,
linux-arm-kernel, linux-kernel
coresight_get_platform_data() takes a reference to the destination
firmware node of each output connection. The core drops those references
on registration failure or when the device is unregistered. Device
resource cleanup alone does not release them.
tpdm_probe() can return before registration if driver data allocation,
MMIO mapping, dataset setup or device name allocation fails. Move the
platform data lookup after these steps so every successful lookup
reaches coresight_register().
Static analysis flagged the TPDM error paths.
Fixes: b3c71626a933 ("Coresight: Add coresight TPDM source driver")
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
drivers/hwtracing/coresight/coresight-tpdm.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-tpdm.c b/drivers/hwtracing/coresight/coresight-tpdm.c
index 8464edbba2d45efa5ba041dae70149a946c20465..f4b879bfca1a153f50012757e1b078605fa87944 100644
--- a/drivers/hwtracing/coresight/coresight-tpdm.c
+++ b/drivers/hwtracing/coresight/coresight-tpdm.c
@@ -1408,11 +1408,6 @@ static int tpdm_probe(struct device *dev, struct resource *res)
struct coresight_desc desc = { 0 };
int ret;
- pdata = coresight_get_platform_data(dev);
- if (IS_ERR(pdata))
- return PTR_ERR(pdata);
- dev->platform_data = pdata;
-
/* driver data*/
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata)
@@ -1448,6 +1443,12 @@ static int tpdm_probe(struct device *dev, struct resource *res)
desc.name = coresight_alloc_device_name("tpdm", dev);
if (!desc.name)
return -ENOMEM;
+
+ pdata = coresight_get_platform_data(dev);
+ if (IS_ERR(pdata))
+ return PTR_ERR(pdata);
+ dev->platform_data = pdata;
+
desc.type = CORESIGHT_DEV_TYPE_SOURCE;
desc.subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_TPDM;
desc.ops = &tpdm_cs_ops;
base-commit: b7d7462c7f973b65de511db6bebb99fb29946ed8
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 2/3] coresight: tnoc: Fix fwnode reference leak on probe failure
2026-12-02 10:09 [PATCH v3 0/3] coresight: Fix fwnode reference leaks on probe failure Yige Jiang
2026-12-02 10:09 ` [PATCH v3 1/3] coresight: tpdm: Fix fwnode reference leak " Yige Jiang
@ 2026-12-02 10:09 ` Yige Jiang
2026-12-02 10:09 ` [PATCH v3 3/3] coresight: tpda: " Yige Jiang
2 siblings, 0 replies; 4+ messages in thread
From: Yige Jiang @ 2026-12-02 10:09 UTC (permalink / raw)
To: Suzuki K Poulose, Alexander Shishkin
Cc: Yige Jiang, Mike Leach, James Clark, Leo Yan, coresight,
linux-arm-kernel, linux-kernel
_tnoc_probe() parses the output connections before allocating driver
data, enabling clocks, mapping registers and setting up the trace ID.
If any of these steps fails, probe returns before coresight_register()
can take ownership of the destination fwnode references.
Get the platform data after trace ID setup. On either lookup or
registration failure, return the ID if the AMBA device acquired one.
The platform-device variant does not allocate a trace ID.
Fixes: e54a52a28a36 ("coresight: add coresight Trace Network On Chip driver")
Suggested-by: James Clark <james.clark@linaro.org>
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
drivers/hwtracing/coresight/coresight-tnoc.c | 22 +++++++++++++-------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-tnoc.c b/drivers/hwtracing/coresight/coresight-tnoc.c
index ec28b439d73d083ffa0de52ef454a9cd54b88175..2f3e2044676358925233c59ff3977fa36555c2c3 100644
--- a/drivers/hwtracing/coresight/coresight-tnoc.c
+++ b/drivers/hwtracing/coresight/coresight-tnoc.c
@@ -191,11 +191,6 @@ static int _tnoc_probe(struct device *dev, struct resource *res)
if (!desc.name)
return -ENOMEM;
- pdata = coresight_get_platform_data(dev);
- if (IS_ERR(pdata))
- return PTR_ERR(pdata);
- dev->platform_data = pdata;
-
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata)
return -ENOMEM;
@@ -217,6 +212,13 @@ static int _tnoc_probe(struct device *dev, struct resource *res)
if (ret)
return ret;
+ pdata = coresight_get_platform_data(dev);
+ if (IS_ERR(pdata)) {
+ ret = PTR_ERR(pdata);
+ goto err_put_id;
+ }
+ dev->platform_data = pdata;
+
desc.ops = &trace_noc_cs_ops;
desc.type = CORESIGHT_DEV_TYPE_LINK;
desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_MERG;
@@ -226,12 +228,16 @@ static int _tnoc_probe(struct device *dev, struct resource *res)
desc.groups = coresight_tnoc_groups;
drvdata->csdev = coresight_register(&desc);
if (IS_ERR(drvdata->csdev)) {
- if (drvdata->atid > 0)
- coresight_trace_id_put_system_id(drvdata->atid);
- return PTR_ERR(drvdata->csdev);
+ ret = PTR_ERR(drvdata->csdev);
+ goto err_put_id;
}
return 0;
+
+err_put_id:
+ if (drvdata->atid > 0)
+ coresight_trace_id_put_system_id(drvdata->atid);
+ return ret;
}
static int trace_noc_probe(struct amba_device *adev, const struct amba_id *id)
base-commit: b7d7462c7f973b65de511db6bebb99fb29946ed8
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 3/3] coresight: tpda: Fix fwnode reference leak on probe failure
2026-12-02 10:09 [PATCH v3 0/3] coresight: Fix fwnode reference leaks on probe failure Yige Jiang
2026-12-02 10:09 ` [PATCH v3 1/3] coresight: tpdm: Fix fwnode reference leak " Yige Jiang
2026-12-02 10:09 ` [PATCH v3 2/3] coresight: tnoc: " Yige Jiang
@ 2026-12-02 10:09 ` Yige Jiang
2 siblings, 0 replies; 4+ messages in thread
From: Yige Jiang @ 2026-12-02 10:09 UTC (permalink / raw)
To: Suzuki K Poulose, Alexander Shishkin
Cc: Yige Jiang, Mike Leach, James Clark, Leo Yan, coresight,
linux-arm-kernel, linux-kernel
tpda_probe() gets the platform data before allocating driver data,
mapping the registers, reserving a trace ID and allocating a device
name. Failure at any of these steps leaves the destination fwnodes of
the output connections referenced because the core has yet to take
ownership of the platform data.
Allocate the name before reserving the trace ID, then get the platform
data immediately before registration. Return the ID if either the
platform data lookup or registration fails.
Fixes: 5b7916625c01 ("Coresight: Add TPDA link driver")
Suggested-by: James Clark <james.clark@linaro.org>
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
drivers/hwtracing/coresight/coresight-tpda.c | 29 +++++++++++++-------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-tpda.c b/drivers/hwtracing/coresight/coresight-tpda.c
index 63a97931246302f74c0d2fb5e70f43d31f0475b9..62e15fc9b6ec9ad7801257ff706778abd2487fa3 100644
--- a/drivers/hwtracing/coresight/coresight-tpda.c
+++ b/drivers/hwtracing/coresight/coresight-tpda.c
@@ -566,11 +566,6 @@ static int tpda_probe(struct amba_device *adev, const struct amba_id *id)
struct coresight_desc desc = { 0 };
void __iomem *base;
- pdata = coresight_get_platform_data(dev);
- if (IS_ERR(pdata))
- return PTR_ERR(pdata);
- adev->dev.platform_data = pdata;
-
drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
if (!drvdata)
return -ENOMEM;
@@ -585,13 +580,21 @@ static int tpda_probe(struct amba_device *adev, const struct amba_id *id)
spin_lock_init(&drvdata->spinlock);
+ desc.name = coresight_alloc_device_name("tpda", dev);
+ if (!desc.name)
+ return -ENOMEM;
+
ret = tpda_init_default_data(drvdata);
if (ret)
return ret;
- desc.name = coresight_alloc_device_name("tpda", dev);
- if (!desc.name)
- return -ENOMEM;
+ pdata = coresight_get_platform_data(dev);
+ if (IS_ERR(pdata)) {
+ ret = PTR_ERR(pdata);
+ goto err_put_id;
+ }
+ adev->dev.platform_data = pdata;
+
desc.type = CORESIGHT_DEV_TYPE_LINK;
desc.subtype.link_subtype = CORESIGHT_DEV_SUBTYPE_LINK_MERG;
desc.ops = &tpda_cs_ops;
@@ -600,13 +603,19 @@ static int tpda_probe(struct amba_device *adev, const struct amba_id *id)
desc.groups = tpda_attr_grps;
desc.access = CSDEV_ACCESS_IOMEM(base);
drvdata->csdev = coresight_register(&desc);
- if (IS_ERR(drvdata->csdev))
- return PTR_ERR(drvdata->csdev);
+ if (IS_ERR(drvdata->csdev)) {
+ ret = PTR_ERR(drvdata->csdev);
+ goto err_put_id;
+ }
pm_runtime_put(&adev->dev);
dev_dbg(drvdata->dev, "TPDA initialized\n");
return 0;
+
+err_put_id:
+ coresight_trace_id_put_system_id(drvdata->atid);
+ return ret;
}
static void tpda_remove(struct amba_device *adev)
base-commit: b7d7462c7f973b65de511db6bebb99fb29946ed8
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 10:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 10:09 [PATCH v3 0/3] coresight: Fix fwnode reference leaks on probe failure Yige Jiang
2026-12-02 10:09 ` [PATCH v3 1/3] coresight: tpdm: Fix fwnode reference leak " Yige Jiang
2026-12-02 10:09 ` [PATCH v3 2/3] coresight: tnoc: " Yige Jiang
2026-12-02 10:09 ` [PATCH v3 3/3] coresight: tpda: " Yige Jiang
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®