[PATCH] coresight: etm4x: fix mis-usage of nr_resource in sysfs interface

Jonathan Zhou jonathan.zhouwen at huawei.com
Wed Sep 2 03:52:56 EDT 2020


The member @nr_resource represents how many resource selector pairs,
and the pair 0 is always implemented and reserved.
So let's multiply by 2 when displaying the implemented resource seletors
and resetting the seletor configuration .
And also update the validation of the input @idx.

Cc: Mathieu Poirier <mathieu.poirier at linaro.org>
Cc: Suzuki K Poulose <suzuki.poulose at arm.com>
Cc: Mike Leach <mike.leach at linaro.org>
Cc: Shaokun Zhang <zhangshaokun at hisilicon.com>
Cc: lizixian at hisilicon.com
Signed-off-by: Jonathan Zhou <jonathan.zhouwen at huawei.com>
---
 drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
index b673e738bc9a..635b93d20efa 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c
@@ -143,8 +143,10 @@ static ssize_t nr_resource_show(struct device *dev,
 {
 	unsigned long val;
 	struct etmv4_drvdata *drvdata = dev_get_drvdata(dev->parent);
-
-	val = drvdata->nr_resource;
+	/* @nr_resource represents how many resource selector pairs,
+	 * hence multiply by 2.
+	 */
+	val = 2 * drvdata->nr_resource;
 	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
 }
 static DEVICE_ATTR_RO(nr_resource);
@@ -236,7 +238,7 @@ static ssize_t reset_store(struct device *dev,
 	}
 
 	config->res_idx = 0x0;
-	for (i = 0; i < drvdata->nr_resource; i++)
+	for (i = 2; i < 2 * drvdata->nr_resource; i++)
 		config->res_ctrl[i] = 0x0;
 
 	config->ss_idx = 0x0;
@@ -1663,8 +1665,11 @@ static ssize_t res_idx_store(struct device *dev,
 
 	if (kstrtoul(buf, 16, &val))
 		return -EINVAL;
-	/* Resource selector pair 0 is always implemented and reserved */
-	if ((val == 0) || (val >= drvdata->nr_resource))
+	/*
+	 * Resource selector pair 0 is always implemented and reserved,
+	 * namely an idx with 0 and 1 is illegal.
+	 */
+	if ((val == 0) || (val == 1) || (val >= 2 * drvdata->nr_resource))
 		return -EINVAL;
 
 	/*
-- 
1.9.1




More information about the linux-arm-kernel mailing list