From f4b335f7f53f741de25cf607760b03d64086223c Mon Sep 17 00:00:00 2001 From: Olav Haugan Date: Tue, 14 Feb 2017 18:20:28 -0800 Subject: 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. Signed-off-by: Olav Haugan Signed-off-by: Mathieu Poirier --- 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(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index d7325c6534ad..491f4da61c11 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -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, diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 26cfac3e6de7..6ddcd186c085 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -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; diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c index ca98ad13bb8c..4cbbd1313331 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c @@ -27,7 +27,7 @@ static ssize_t nr_addr_cmp_show(struct device *dev, struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); val = drvdata->nr_addr_cmp; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static DEVICE_ATTR_RO(nr_addr_cmp); @@ -37,7 +37,7 @@ static ssize_t nr_cntr_show(struct device *dev, struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); val = drvdata->nr_cntr; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static DEVICE_ATTR_RO(nr_cntr); @@ -48,7 +48,7 @@ static ssize_t nr_ctxid_cmp_show(struct device *dev, struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent); val = drvdata->nr_ctxid_cmp; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static DEVICE_ATTR_RO(nr_ctxid_cmp); @@ -68,7 +68,7 @@ static ssize_t etmsr_show(struct device *dev, spin_unlock_irqrestore(&drvdata->spinlock, flags); pm_runtime_put(drvdata->dev); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static DEVICE_ATTR_RO(etmsr); @@ -110,7 +110,7 @@ static ssize_t mode_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->mode; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t mode_store(struct device *dev, @@ -195,7 +195,7 @@ static ssize_t trigger_event_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->trigger_event; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t trigger_event_store(struct device *dev, @@ -225,7 +225,7 @@ static ssize_t enable_event_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->enable_event; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t enable_event_store(struct device *dev, @@ -255,7 +255,7 @@ static ssize_t fifofull_level_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->fifofull_level; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t fifofull_level_store(struct device *dev, @@ -285,7 +285,7 @@ static ssize_t addr_idx_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->addr_idx; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t addr_idx_store(struct device *dev, @@ -335,7 +335,7 @@ static ssize_t addr_single_show(struct device *dev, val = config->addr_val[idx]; spin_unlock(&drvdata->spinlock); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t addr_single_store(struct device *dev, @@ -394,7 +394,7 @@ static ssize_t addr_range_show(struct device *dev, val2 = config->addr_val[idx + 1]; spin_unlock(&drvdata->spinlock); - return sprintf(buf, "%#lx %#lx\n", val1, val2); + return scnprintf(buf, PAGE_SIZE, "%#lx %#lx\n", val1, val2); } static ssize_t addr_range_store(struct device *dev, @@ -456,7 +456,7 @@ static ssize_t addr_start_show(struct device *dev, val = config->addr_val[idx]; spin_unlock(&drvdata->spinlock); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t addr_start_store(struct device *dev, @@ -510,7 +510,7 @@ static ssize_t addr_stop_show(struct device *dev, val = config->addr_val[idx]; spin_unlock(&drvdata->spinlock); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t addr_stop_store(struct device *dev, @@ -556,7 +556,7 @@ static ssize_t addr_acctype_show(struct device *dev, val = config->addr_acctype[config->addr_idx]; spin_unlock(&drvdata->spinlock); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t addr_acctype_store(struct device *dev, @@ -588,7 +588,7 @@ static ssize_t cntr_idx_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->cntr_idx; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t cntr_idx_store(struct device *dev, @@ -629,7 +629,7 @@ static ssize_t cntr_rld_val_show(struct device *dev, val = config->cntr_rld_val[config->cntr_idx]; spin_unlock(&drvdata->spinlock); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t cntr_rld_val_store(struct device *dev, @@ -664,7 +664,7 @@ static ssize_t cntr_event_show(struct device *dev, val = config->cntr_event[config->cntr_idx]; spin_unlock(&drvdata->spinlock); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t cntr_event_store(struct device *dev, @@ -699,7 +699,7 @@ static ssize_t cntr_rld_event_show(struct device *dev, val = config->cntr_rld_event[config->cntr_idx]; spin_unlock(&drvdata->spinlock); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t cntr_rld_event_store(struct device *dev, @@ -734,7 +734,7 @@ static ssize_t cntr_val_show(struct device *dev, if (!local_read(&drvdata->mode)) { spin_lock(&drvdata->spinlock); for (i = 0; i < drvdata->nr_cntr; i++) - ret += sprintf(buf, "counter %d: %x\n", + ret += scnprintf(buf, PAGE_SIZE, "counter %d: %x\n", i, config->cntr_val[i]); spin_unlock(&drvdata->spinlock); return ret; @@ -742,7 +742,7 @@ static ssize_t cntr_val_show(struct device *dev, for (i = 0; i < drvdata->nr_cntr; i++) { val = etm_readl(drvdata, ETMCNTVRn(i)); - ret += sprintf(buf, "counter %d: %x\n", i, val); + ret += scnprintf(buf, PAGE_SIZE, "counter %d: %x\n", i, val); } return ret; @@ -777,7 +777,7 @@ static ssize_t seq_12_event_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->seq_12_event; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t seq_12_event_store(struct device *dev, @@ -806,7 +806,7 @@ static ssize_t seq_21_event_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->seq_21_event; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t seq_21_event_store(struct device *dev, @@ -835,7 +835,7 @@ static ssize_t seq_23_event_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->seq_23_event; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t seq_23_event_store(struct device *dev, @@ -864,7 +864,7 @@ static ssize_t seq_31_event_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->seq_31_event; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t seq_31_event_store(struct device *dev, @@ -893,7 +893,7 @@ static ssize_t seq_32_event_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->seq_32_event; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t seq_32_event_store(struct device *dev, @@ -922,7 +922,7 @@ static ssize_t seq_13_event_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->seq_13_event; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t seq_13_event_store(struct device *dev, @@ -965,7 +965,7 @@ static ssize_t seq_curr_state_show(struct device *dev, spin_unlock_irqrestore(&drvdata->spinlock, flags); pm_runtime_put(drvdata->dev); out: - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t seq_curr_state_store(struct device *dev, @@ -998,7 +998,7 @@ static ssize_t ctxid_idx_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->ctxid_idx; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t ctxid_idx_store(struct device *dev, @@ -1040,7 +1040,7 @@ static ssize_t ctxid_pid_show(struct device *dev, val = config->ctxid_vpid[config->ctxid_idx]; spin_unlock(&drvdata->spinlock); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t ctxid_pid_store(struct device *dev, @@ -1075,7 +1075,7 @@ static ssize_t ctxid_mask_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->ctxid_mask; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t ctxid_mask_store(struct device *dev, @@ -1104,7 +1104,7 @@ static ssize_t sync_freq_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->sync_freq; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t sync_freq_store(struct device *dev, @@ -1133,7 +1133,7 @@ static ssize_t timestamp_event_show(struct device *dev, struct etm_config *config = &drvdata->config; val = config->timestamp_event; - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t timestamp_event_store(struct device *dev, @@ -1174,7 +1174,7 @@ static ssize_t traceid_show(struct device *dev, val = etm_get_trace_id(drvdata); - return sprintf(buf, "%#lx\n", val); + return scnprintf(buf, PAGE_SIZE, "%#lx\n", val); } static ssize_t traceid_store(struct device *dev, diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/drivers/hwtracing/coresight/coresight-funnel.c index 860fe6ef5632..30cfd5c12b71 100644 --- a/drivers/hwtracing/coresight/coresight-funnel.c +++ b/drivers/hwtracing/coresight/coresight-funnel.c @@ -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); diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c index 93fc26f01bab..70b3eee7f4dd 100644 --- a/drivers/hwtracing/coresight/coresight-stm.c +++ b/drivers/hwtracing/coresight/coresight-stm.c @@ -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, diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c index d8517d2a968c..1a660f014c6c 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.c +++ b/drivers/hwtracing/coresight/coresight-tmc.c @@ -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, -- cgit v1.2.3 From ad5bfbe2f500ea93751b759e4fb78aa52f1d23bf Mon Sep 17 00:00:00 2001 From: Olav Haugan Date: Tue, 14 Feb 2017 18:20:29 -0800 Subject: coresight: etm3x: Correctly output counter values in sysfs node cntr_val_show function does not print the intended information. It is only printing the latest counter value. Fix this. Signed-off-by: Olav Haugan Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c index 4cbbd1313331..62acf07d604b 100644 --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c @@ -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; -- cgit v1.2.3 From 6de8ad2f92ea640f715142201653c66564eb055a Mon Sep 17 00:00:00 2001 From: Mike Leach Date: Fri, 17 Feb 2017 19:10:11 +0000 Subject: coresight: Fixes coresight DT parse to get correct output port ID. 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 endpoint { } } Existing code read endpoint number - always 0x0, rather than the correct port number. Signed-off-by: Mike Leach Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/of_coresight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/of_coresight.c b/drivers/hwtracing/coresight/of_coresight.c index 629e031b7456..09142e99e915 100644 --- a/drivers/hwtracing/coresight/of_coresight.c +++ b/drivers/hwtracing/coresight/of_coresight.c @@ -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 -- cgit v1.2.3 From 3e00ccb2e7f6f51bf94418c85c2d0c1a639613f5 Mon Sep 17 00:00:00 2001 From: Suzuki K Poulose Date: Wed, 29 Mar 2017 17:33:34 +0100 Subject: coresight: Disable the path only when the source is disabled With a coresight tracing session, the components along the path from the source to sink are disabled after the source is disabled. However, if the source was not actually disabled due to active users, we should not disable the components in the path. Cc: Mathieu Poirier Signed-off-by: Suzuki K Poulose Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 0c37356e417c..532a2acfa8cc 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -253,14 +253,22 @@ static int coresight_enable_source(struct coresight_device *csdev, u32 mode) return 0; } -static void coresight_disable_source(struct coresight_device *csdev) +/** + * coresight_disable_source - Drop the reference count by 1 and disable + * the device if there are no users left. + * + * @csdev - The coresight device to disable + * + * Returns true if the device has been disabled. + */ +static bool coresight_disable_source(struct coresight_device *csdev) { if (atomic_dec_return(csdev->refcnt) == 0) { - if (source_ops(csdev)->disable) { + if (source_ops(csdev)->disable) source_ops(csdev)->disable(csdev, NULL); - csdev->enable = false; - } + csdev->enable = false; } + return !csdev->enable; } void coresight_disable_path(struct list_head *path) @@ -629,7 +637,7 @@ void coresight_disable(struct coresight_device *csdev) if (ret) goto out; - if (!csdev->enable) + if (!csdev->enable || !coresight_disable_source(csdev)) goto out; switch (csdev->subtype.source_subtype) { @@ -647,7 +655,6 @@ void coresight_disable(struct coresight_device *csdev) break; } - coresight_disable_source(csdev); coresight_disable_path(path); coresight_release_path(path); -- cgit v1.2.3 From c749b99b9adefa6291977edef2349e5ea3a0a56a Mon Sep 17 00:00:00 2001 From: Suzuki K Poulose Date: Wed, 29 Mar 2017 17:33:35 +0100 Subject: coresight: Fix reference count for software sources For software sources (i.e STM), there could be multiple agents generating the trace data, unlike the ETMs. So we need to properly do the accounting for the active number of users to disable the device when the last user goes away. Right now, the reference counting is broken for sources as we skip the actions when we detect that the source is enabled. This patch fixes the problem by adding the refcounting for software sources, even when they are enabled. Cc: Mathieu Poirier Reported-by: Robert Walker Signed-off-by: Suzuki K Poulose Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 532a2acfa8cc..6a0202b7384f 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -558,6 +558,9 @@ int coresight_enable(struct coresight_device *csdev) int cpu, ret = 0; struct coresight_device *sink; struct list_head *path; + enum coresight_dev_subtype_source subtype; + + subtype = csdev->subtype.source_subtype; mutex_lock(&coresight_mutex); @@ -565,8 +568,16 @@ int coresight_enable(struct coresight_device *csdev) if (ret) goto out; - if (csdev->enable) + if (csdev->enable) { + /* + * There could be multiple applications driving the software + * source. So keep the refcount for each such user when the + * source is already enabled. + */ + if (subtype == CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE) + atomic_inc(csdev->refcnt); goto out; + } /* * Search for a valid sink for this session but don't reset the @@ -593,7 +604,7 @@ int coresight_enable(struct coresight_device *csdev) if (ret) goto err_source; - switch (csdev->subtype.source_subtype) { + switch (subtype) { case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC: /* * When working from sysFS it is important to keep track -- cgit v1.2.3