Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 3/3] coresight: tpda: Fix fwnode reference leak on probe failure
@ 2026-11-26 15:57 Yige Jiang
  0 siblings, 0 replies; only message in thread
From: Yige Jiang @ 2026-11-26 15:57 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.

Codex helped check trace ID ownership and draft the probe changes.

Fixes: 5b7916625c01 ("Coresight: Add TPDA link driver")
Suggested-by: James Clark <james.clark@linaro.org>
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
v2: Add the TPDA fix identified during review of the TPDM patch.

v1: https://lore.kernel.org/all/rc-b1-20261110-vc-178-2d9055f946c8@gmail.com/
Review: https://lore.kernel.org/all/e06bd559-c8c5-4e82-8951-9f7894cfb378@linaro.org/

Compile-tested: arm64, GCC 14.2.0, W=1, coresight-tpda.o.
The baseline and patched objects built without warnings.
No hardware or runtime tests were performed.

 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 related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-26 15:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 15:57 [PATCH v2 3/3] coresight: tpda: Fix fwnode reference leak on probe failure Yige Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox