[PATCH v12 03/14] coresight: etm3x: prohibit modifying cntr_val and reset while session is enabled

From: Yeoreum Yun

Date: Thu Sep 24 2026 - 13:50:53 EST


cntr_val are overwritten with the values read from the corresponding
registers by etm_disable_hw() when the session is disabled.

This means that any changes to this value made while the session is
enabled would be lost when the session is disabled.

Also, reset shouldn't be called while session is enabled.

Therefore, prohibit modifying cntr_val and reset while the session is enabled.

Reviewed-by: Mike Leach <mike.leach@xxxxxxx>
Tested-by: Leo Yan <leo.yan@xxxxxxx>
Signed-off-by: Yeoreum Yun <yeoreum.yun@xxxxxxx>
---
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
index b3c67e96a82a..cdb70a4382eb 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
@@ -75,6 +75,10 @@ static ssize_t reset_store(struct device *dev,
if (ret)
return ret;

+ if (IS_ERR_OR_NULL(drvdata->csdev) ||
+ coresight_get_mode(drvdata->csdev))
+ return -EBUSY;
+
if (val) {
spin_lock(&drvdata->spinlock);
memset(config, 0, sizeof(struct etm_config));
@@ -744,6 +748,9 @@ static ssize_t cntr_val_store(struct device *dev,
ret = kstrtoul(buf, 16, &val);
if (ret)
return ret;
+ if (IS_ERR_OR_NULL(drvdata->csdev) ||
+ coresight_get_mode(drvdata->csdev))
+ return -EBUSY;

spin_lock(&drvdata->spinlock);
config->cntr_val[config->cntr_idx] = val;

--
2.43.0