Skip to contentSkip to conversation

coresight: tpdm: Fix fwnode reference leak on probe failure

PATCH New Yige Jiang 1 participant 1 message Nov 26

Subsystems (2)
lore
Share & tools
lore

Yige Jiang

author
#0 lore raw

PATCH v2 1/3 coresight: tpdm: Fix fwnode reference leak on probe failure

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. Codex helped prepare the change and describe how the references are released.

Fixes b3c71626a933 ("Coresight: Add coresight TPDM source driver")

---
v2: Rebase the TPDM fix on the CoreSight next tree. Add separate
fixes for TNOC and TPDA following review of v1.

v1: https://lore.kernel.org/all/[email protected]/
Review: https://lore.kernel.org/all/[email protected]/

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

 drivers/hwtracing/coresight/coresight-tpdm.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/hwtracing/coresight/coresight-tpdm.c +6 -5
index 8464edbba2d45efa5ba041dae70149a946c20465..f4b879bfca1a153f50012757e1b078605fa87944 100644
@@ -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