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 2/2] coresight: tmc: fix the reserved memory mapping leak
Date: Mon, 30 Nov 2026 17:22:26 +0800 [thread overview]
Message-ID: <20261130-fix-tmc-issues-v1-2-fb0893a65bea@oss.qualcomm.com> (raw)
In-Reply-To: <20261130-fix-tmc-issues-v1-0-fb0893a65bea@oss.qualcomm.com>
tmc_get_reserved_region() maps the reserved trace buffer and crash
metadata regions with memremap(), but never unmaps them, neither when
the probe fails nor when the device is removed.
Use devm_memremap() so that the mappings are released with the device.
devm_memremap() returns an error pointer on failure, so only store a
mapping once it succeeded, keeping the buffer pointer NULL otherwise as
tmc_has_reserved_buffer() and tmc_has_crash_mdata_buffer() expect.
Fixes: 91a2086aa6d1 ("coresight: tmc-etr: Add support to use reserved trace memory")
Fixes: 6dbcbcfc4496 ("coresight: tmc: Enable panic sync handling")
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 | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-tmc-core.c b/drivers/hwtracing/coresight/coresight-tmc-core.c
index 754a9b10b7d2..fd653cfbd4ae 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-core.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -646,32 +646,33 @@ static void tmc_get_reserved_region(struct device *parent)
{
struct tmc_drvdata *drvdata = dev_get_drvdata(parent);
struct resource res;
+ void *vaddr;
if (of_tmc_get_reserved_resource_by_name(parent, "tracedata", &res))
return;
- drvdata->resrv_buf.vaddr = memremap(res.start,
- resource_size(&res),
- MEMREMAP_WC);
- if (IS_ERR_OR_NULL(drvdata->resrv_buf.vaddr)) {
+ vaddr = devm_memremap(parent, res.start, resource_size(&res),
+ MEMREMAP_WC);
+ if (IS_ERR(vaddr)) {
dev_err(parent, "Reserved trace buffer mapping failed\n");
return;
}
+ drvdata->resrv_buf.vaddr = vaddr;
drvdata->resrv_buf.paddr = res.start;
drvdata->resrv_buf.size = resource_size(&res);
if (of_tmc_get_reserved_resource_by_name(parent, "metadata", &res))
return;
- drvdata->crash_mdata.vaddr = memremap(res.start,
- resource_size(&res),
- MEMREMAP_WC);
- if (IS_ERR_OR_NULL(drvdata->crash_mdata.vaddr)) {
+ vaddr = devm_memremap(parent, res.start, resource_size(&res),
+ MEMREMAP_WC);
+ if (IS_ERR(vaddr)) {
dev_err(parent, "Metadata memory mapping failed\n");
return;
}
+ drvdata->crash_mdata.vaddr = vaddr;
drvdata->crash_mdata.paddr = res.start;
drvdata->crash_mdata.size = resource_size(&res);
}
--
2.34.1
prev parent reply other threads:[~2026-11-30 9:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 9:22 [PATCH 0/2] Fix TMC resource leak issues Jie Gan
2026-11-30 9:22 ` [PATCH 1/2] coresight: tmc: register the crash data interface only on probe success Jie Gan
2026-11-30 9:22 ` Jie Gan [this message]
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=20261130-fix-tmc-issues-v1-2-fb0893a65bea@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