Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jie Gan <jie.gan@oss.qualcomm.com>
To: Suzuki K Poulose <suzuki.poulose@arm.com>,
	Mike Leach <mike.leach@arm.com>,
	James Clark <james.clark@linaro.org>, Leo Yan <leo.yan@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Tanmay Jagdale <tanmay@marvell.com>,
	Anil Kumar Reddy <areddy3@marvell.com>,
	Linu Cherian <lcherian@marvell.com>,
	Tingwei Zhang <tingwei.zhang@oss.qualcomm.com>
Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
	Jie Gan <jie.gan@oss.qualcomm.com>,
	Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v2 1/2] coresight: tmc: register the crash data interface only on probe success
Date: Tue, 01 Dec 2026 09:27:22 +0800	[thread overview]
Message-ID: <20261201-fix-tmc-issues-v2-1-e3fdf7ab0ed5@oss.qualcomm.com> (raw)
In-Reply-To: <20261201-fix-tmc-issues-v2-0-e3fdf7ab0ed5@oss.qualcomm.com>

The crash data interface is registered after the out label of
__tmc_probe(), which every error path jumps to. When the probe fails
while the reserved regions hold valid crash data,
is_tmc_crashdata_valid() and tmc_prepare_crashdata() log through
drvdata->csdev, which is then NULL, an error pointer or an unregistered
device, and register_crash_dev_interface() can register a misc device
whose driver data is freed when the probe failure is unwound.

Only register the crash data interface once the probe has succeeded.
The out label then only returns the error code, so return directly
from the error paths instead.

Fixes: d58a70bdab57 ("coresight: tmc: Add support for reading crash data")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-f23df7b7-bae5-4fa0-96ef-4e83632058e8
Signed-off-by: Jie Gan <jie.gan@oss.qualcomm.com>
---
 drivers/hwtracing/coresight/coresight-tmc-core.c | 37 +++++++++---------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
index 0ef4b817b297..7ed1a9720a0e 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-core.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -784,14 +784,10 @@ static int __tmc_probe(struct device *dev, struct resource *res)
 	if (ret)
 		return ret;
 
-	ret = -ENOMEM;
-
 	/* Validity for the resource is already checked by the AMBA core */
 	base = devm_ioremap_resource(dev, res);
-	if (IS_ERR(base)) {
-		ret = PTR_ERR(base);
-		goto out;
-	}
+	if (IS_ERR(base))
+		return PTR_ERR(base);
 
 	drvdata->base = base;
 	desc.access = CSDEV_ACCESS_IOMEM(base);
@@ -831,7 +827,7 @@ static int __tmc_probe(struct device *dev, struct resource *res)
 		desc.ops = &tmc_etr_cs_ops;
 		ret = tmc_etr_setup_caps(dev, devid, &desc.access);
 		if (ret)
-			goto out;
+			return ret;
 		idr_init(&drvdata->idr);
 		mutex_init(&drvdata->idr_mutex);
 		dev_list = "tmc_etr";
@@ -846,30 +842,23 @@ static int __tmc_probe(struct device *dev, struct resource *res)
 		break;
 	default:
 		pr_err("%s: Unsupported TMC config\n", desc.name);
-		ret = -EINVAL;
-		goto out;
+		return -EINVAL;
 	}
 
 	desc.name = coresight_alloc_device_name(dev_list, dev);
-	if (!desc.name) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	if (!desc.name)
+		return -ENOMEM;
 
 	pdata = coresight_get_platform_data(dev);
-	if (IS_ERR(pdata)) {
-		ret = PTR_ERR(pdata);
-		goto out;
-	}
+	if (IS_ERR(pdata))
+		return PTR_ERR(pdata);
 	dev->platform_data = pdata;
 	desc.pdata = pdata;
 
 	coresight_clear_self_claim_tag(&desc.access);
 	drvdata->csdev = coresight_register(&desc);
-	if (IS_ERR(drvdata->csdev)) {
-		ret = PTR_ERR(drvdata->csdev);
-		goto out;
-	}
+	if (IS_ERR(drvdata->csdev))
+		return PTR_ERR(drvdata->csdev);
 
 	drvdata->miscdev.name = desc.name;
 	drvdata->miscdev.minor = MISC_DYNAMIC_MINOR;
@@ -877,14 +866,14 @@ static int __tmc_probe(struct device *dev, struct resource *res)
 	ret = misc_register(&drvdata->miscdev);
 	if (ret) {
 		coresight_unregister(drvdata->csdev);
-		goto out;
+		return ret;
 	}
 
-out:
 	if (is_tmc_crashdata_valid(drvdata) &&
 	    !tmc_prepare_crashdata(drvdata))
 		register_crash_dev_interface(drvdata, desc.name);
-	return ret;
+
+	return 0;
 }
 
 static int tmc_probe(struct amba_device *adev, const struct amba_id *id)

-- 
2.34.1



  reply	other threads:[~2026-12-01  1:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  1:27 [PATCH v2 0/2] Fix TMC resource leak issues Jie Gan
2026-12-01  1:27 ` Jie Gan [this message]
2026-12-01  1:27 ` [PATCH v2 2/2] coresight: tmc: fix the reserved memory mapping leak Jie Gan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201-fix-tmc-issues-v2-1-e3fdf7ab0ed5@oss.qualcomm.com \
    --to=jie.gan@oss.qualcomm.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=areddy3@marvell.com \
    --cc=coresight@lists.linaro.org \
    --cc=james.clark@linaro.org \
    --cc=lcherian@marvell.com \
    --cc=leo.yan@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mike.leach@arm.com \
    --cc=sashiko-bot@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=tanmay@marvell.com \
    --cc=tingwei.zhang@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox