Skip to contentSkip to conversation

coresight: next v4.11-rc4

PATCH New Mathieu Poirier 3 participants 7 messages Mar 27, 2017 – Apr 24, 2017

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

cover coresight: next v4.11-rc4

Good morning,

Just a few patches this time around - please consider for inclusion in the 4.12 cycle. Everything applies on your 'char-misc-next' branch (57c0eabbd57e).

Thanks,
Mathieu

Mike Leach (1):
coresight: Fixes coresight DT parse to get correct output port ID.

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 +-
 drivers/hwtracing/coresight/of_coresight.c         |  2 +-
 7 files changed, 52 insertions(+), 42 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 coresight: Replace sprintf with scnprintf

From: Olav Haugan <[email protected]>

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.7.4
#2 lore raw

PATCH 1/3 coresight: Replace sprintf with scnprintf

Quoted 4 lines · Mathieu Poirier

From: Olav Haugan <[email protected]>

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

But it's totally pointless here :(

Quoted 17 lines
---
 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 +0 -0
index d7325c6534ad..491f4da61c11 100644

drivers/hwtracing/coresight/coresight-etb10.c static ssize_t trigger_cntr_show(struct device *dev, · line 591

Quoted 5 lines
drivers/hwtracing/coresight/coresight-etb10.c +1 -1
@@ -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);

There is no need for this in sysfs show callbacks. You _know_ this is a PAGE_SIZE buffer, and that you can not overflow it with a simple number.

So don't change these types of functions for no reason please.

Same for most of this patch.

thanks,

greg k-h

#3 lore raw

PATCH 1/3 coresight: Replace sprintf with scnprintf

Quoted 8 lines · Greg KH
Quoted 4 lines · Mathieu Poirier

From: Olav Haugan <[email protected]>

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

But it's totally pointless here :(

The driver is using a mix of sprintf and scnprintf. This patch is making the usage consistent across the driver. (There is actually more scnprintf usage than sprintf usage.) Consistency is good. What is the harm?

Quoted 34 lines
Quoted 17 lines
---
 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 +0 -0
index d7325c6534ad..491f4da61c11 100644

drivers/hwtracing/coresight/coresight-etb10.c static ssize_t trigger_cntr_show(struct device *dev, · line 591

Quoted 5 lines
drivers/hwtracing/coresight/coresight-etb10.c +1 -1
@@ -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);

There is no need for this in sysfs show callbacks. You _know_ this is a PAGE_SIZE buffer, and that you can not overflow it with a simple number.

So don't change these types of functions for no reason please.

Same for most of this patch.

thanks,

greg k-h

Signature · 4 lines
.Olav

The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw

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

In reply to Mathieu Poirier

From: Olav Haugan <[email protected]>

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.7.4
#5 lore raw

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

Quoted 24 lines · Mathieu Poirier

From: Olav Haugan <[email protected]>

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 +1 -1
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++)

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c static ssize_t cntr_val_show(struct device *dev, · line 744

Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +8 -2
-			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;
+		}

This is NOT a one-value-per-file thing. That needs to be fixed, don't try to make it worse here. You are not following the proper sysfs rules.

I can't take this, sorry.

greg k-h

#6 lore raw

PATCH 3/3 coresight: Fixes coresight DT parse to get correct output port ID.

In reply to Mathieu Poirier

From: Mike Leach <[email protected]>

Corrected to get the port numbering to allow programmable replicator driver to operate correctly.

By convention, CoreSight devices number ports, not endpoints in the .dts files:-

port {
     reg<N>
     endpoint {
     }
}

Existing code read endpoint number - always 0x0, rather than the correct port number.

---
 drivers/hwtracing/coresight/of_coresight.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwtracing/coresight/of_coresight.c +1 -1
index 629e031b7456..09142e99e915 100644
@@ -149,7 +149,7 @@ struct coresight_platform_data *of_get_coresight_platform_data(
 				continue;
 
 			/* The local out port number */
-			pdata->outports[i] = endpoint.id;
+			pdata->outports[i] = endpoint.port;
 
 			/*
 			 * Get a handle on the remote port and parent
Signature · 1 line
2.7.4