Skip to contentSkip to conversation

coresight: Replace sprintf with scnprintf + bug fix

PATCH New Olav Haugan 2 participants 4 messages Feb 15, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover coresight: Replace sprintf with scnprintf + bug fix

Replaced all occurrences of s{n}printf with scnprintf for consistency across coresight files.
While doing that found a bug in one of the show functions which I also fixed (second patch).

Olav Haugan (2):
coresight: Replace sprintf with scnprintf
coresight: etm3x: Correctly output counter values in sysfs node

 drivers/hwtracing/coresight/coresight-etb10.c      |  2 +-
 drivers/hwtracing/coresight/coresight-etm-perf.c   |  2 +-
 .../hwtracing/coresight/coresight-etm3x-sysfs.c    | 80 ++++++++++++----------
 drivers/hwtracing/coresight/coresight-funnel.c     |  4 +-
 drivers/hwtracing/coresight/coresight-stm.c        |  2 +-
 drivers/hwtracing/coresight/coresight-tmc.c        |  2 +-
 6 files changed, 51 insertions(+), 41 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/2 coresight: Replace sprintf with scnprintf

Replace all occurrences of sprintf with scnprintf in coresight driver for consistency. scnprintf is also a safer alternative to sprintf.

---
 drivers/hwtracing/coresight/coresight-etb10.c      |  2 +-
 drivers/hwtracing/coresight/coresight-etm-perf.c   |  2 +-
 .../hwtracing/coresight/coresight-etm3x-sysfs.c    | 66 +++++++++++-----------
 drivers/hwtracing/coresight/coresight-funnel.c     |  4 +-
 drivers/hwtracing/coresight/coresight-stm.c        |  2 +-
 drivers/hwtracing/coresight/coresight-tmc.c        |  2 +-
 6 files changed, 39 insertions(+), 39 deletions(-)
drivers/hwtracing/coresight/coresight-etb10.c +1 -1
index d7325c6534ad..491f4da61c11 100644
@@ -588,7 +588,7 @@ static ssize_t trigger_cntr_show(struct device *dev,
 	struct etb_drvdata *drvdata = dev_get_drvdata(dev->parent);
 	unsigned long val = drvdata->trigger_cntr;
 
-	return sprintf(buf, "%#lx\n", val);
+	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
 }
 
 static ssize_t trigger_cntr_store(struct device *dev,
drivers/hwtracing/coresight/coresight-etm-perf.c +1 -1
index 26cfac3e6de7..6ddcd186c085 100644
@@ -467,7 +467,7 @@ int etm_perf_symlink(struct coresight_device *csdev, bool link)
 	struct device *pmu_dev = etm_pmu.dev;
 	struct device *cs_dev = &csdev->dev;
 
-	sprintf(entry, "cpu%d", cpu);
+	scnprintf(entry, PAGE_SIZE, "cpu%d", cpu);
 
 	if (!etm_perf_up)
 		return -EPROBE_DEFER;
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +33 -33

264 lines not on this page · raw message

drivers/hwtracing/coresight/coresight-funnel.c +2 -2
index 860fe6ef5632..30cfd5c12b71 100644
@@ -114,7 +114,7 @@ static ssize_t priority_show(struct device *dev,
 	struct funnel_drvdata *drvdata = dev_get_drvdata(dev->parent);
 	unsigned long val = drvdata->priority;
 
-	return sprintf(buf, "%#lx\n", val);
+	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
 }
 
 static ssize_t priority_store(struct device *dev,
@@ -157,7 +157,7 @@ static ssize_t funnel_ctrl_show(struct device *dev,
 
 	pm_runtime_put(drvdata->dev);
 
-	return sprintf(buf, "%#x\n", val);
+	return scnprintf(buf, PAGE_SIZE, "%#x\n", val);
 }
 static DEVICE_ATTR_RO(funnel_ctrl);
 
drivers/hwtracing/coresight/coresight-stm.c +1 -1
index 93fc26f01bab..70b3eee7f4dd 100644
@@ -614,7 +614,7 @@ static ssize_t traceid_show(struct device *dev,
 	struct stm_drvdata *drvdata = dev_get_drvdata(dev->parent);
 
 	val = drvdata->traceid;
-	return sprintf(buf, "%#lx\n", val);
+	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
 }
 
 static ssize_t traceid_store(struct device *dev,
drivers/hwtracing/coresight/coresight-tmc.c +1 -1
index d8517d2a968c..1a660f014c6c 100644
@@ -253,7 +253,7 @@ static ssize_t trigger_cntr_show(struct device *dev,
 	struct tmc_drvdata *drvdata = dev_get_drvdata(dev->parent);
 	unsigned long val = drvdata->trigger_cntr;
 
-	return sprintf(buf, "%#lx\n", val);
+	return scnprintf(buf, PAGE_SIZE, "%#lx\n", val);
 }
 
 static ssize_t trigger_cntr_store(struct device *dev,
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/2 coresight: etm3x: Correctly output counter values in sysfs node

In reply to Olav Haugan

cntr_val_show function does not print the intended information. It is only printing the latest counter value. Fix this.

---
 drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +14 -4
index 4cbbd1313331..62acf07d604b 100644
@@ -730,19 +730,29 @@ static ssize_t cntr_val_show(struct device *dev,
 	u32 val;
 	struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
 	struct etm_config *config = &drvdata->config;
+	int buf_size = PAGE_SIZE;
 
 	if (!local_read(&drvdata->mode)) {
 		spin_lock(&drvdata->spinlock);
-		for (i = 0; i < drvdata->nr_cntr; i++)
-			ret += scnprintf(buf, PAGE_SIZE, "counter %d: %x\n",
-				       i, config->cntr_val[i]);
+		for (i = 0; i < drvdata->nr_cntr; i++) {
+			ret += scnprintf(&buf[ret], buf_size,
+					 "counter %d: %x\n",
+					 i, config->cntr_val[i]);
+			buf_size -= ret;
+			if (buf_size <= 0)
+				break;
+		}
 		spin_unlock(&drvdata->spinlock);
 		return ret;
 	}
 
 	for (i = 0; i < drvdata->nr_cntr; i++) {
 		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += scnprintf(buf, PAGE_SIZE, "counter %d: %x\n", i, val);
+		ret += scnprintf(&buf[ret], buf_size,
+				 "counter %d: %x\n", i, val);
+		buf_size -= ret;
+		if (buf_size <= 0)
+			break;
 	}
 
 	return ret;
Signature · 1 line
2.11.0
#3 lore raw

cover coresight: Replace sprintf with scnprintf + bug fix

In reply to Olav Haugan
Quoted 9 lines · Olav Haugan

Replaced all occurrences of s{n}printf with scnprintf for consistency across coresight files.
While doing that found a bug in one of the show functions which I also fixed (second patch).

Olav Haugan (2):
coresight: Replace sprintf with scnprintf
coresight: etm3x: Correctly output counter values in sysfs node

Quoted 8 lines
 drivers/hwtracing/coresight/coresight-etb10.c      |  2 +-
 drivers/hwtracing/coresight/coresight-etm-perf.c   |  2 +-
 .../hwtracing/coresight/coresight-etm3x-sysfs.c    | 80 ++++++++++++----------
 drivers/hwtracing/coresight/coresight-funnel.c     |  4 +-
 drivers/hwtracing/coresight/coresight-stm.c        |  2 +-
 drivers/hwtracing/coresight/coresight-tmc.c        |  2 +-
 6 files changed, 51 insertions(+), 41 deletions(-)

I have applied both patches - thanks,
Mathieu

Quoted 3 lines

--
2.11.0