2021-02-04 03:36:04

by Jiapeng Chong

[permalink] [raw]
Subject: [PATCH] drivers/perf: convert sysfs sprintf/snprintf family to sysfs_emit

Fix the following coccicheck warning:

./drivers/perf/arm-cci.c:708:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-cci.c:699:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-cci.c:528:8-16: WARNING: use scnprintf or sprintf.
./drivers/perf/arm-cci.c:309:8-16: WARNING: use scnprintf or sprintf.

Reported-by: Abaci Robot<[email protected]>
Signed-off-by: Jiapeng Chong <[email protected]>
---
drivers/perf/arm-cci.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c
index 87c4be9..efc39cb 100644
--- a/drivers/perf/arm-cci.c
+++ b/drivers/perf/arm-cci.c
@@ -306,7 +306,7 @@ static ssize_t cci400_pmu_cycle_event_show(struct device *dev,
{
struct dev_ext_attribute *eattr = container_of(attr,
struct dev_ext_attribute, attr);
- return snprintf(buf, PAGE_SIZE, "config=0x%lx\n", (unsigned long)eattr->var);
+ return sysfs_emit(buf, "config=0x%lx\n", (unsigned long)eattr->var);
}

static int cci400_get_event_idx(struct cci_pmu *cci_pmu,
@@ -525,8 +525,8 @@ static ssize_t cci5xx_pmu_global_event_show(struct device *dev,
struct dev_ext_attribute *eattr = container_of(attr,
struct dev_ext_attribute, attr);
/* Global events have single fixed source code */
- return snprintf(buf, PAGE_SIZE, "event=0x%lx,source=0x%x\n",
- (unsigned long)eattr->var, CCI5xx_PORT_GLOBAL);
+ return sysfs_emit(buf, "event=0x%lx,source=0x%x\n",
+ (unsigned long)eattr->var, CCI5xx_PORT_GLOBAL);
}

/*
@@ -696,7 +696,7 @@ static ssize_t cci_pmu_format_show(struct device *dev,
{
struct dev_ext_attribute *eattr = container_of(attr,
struct dev_ext_attribute, attr);
- return snprintf(buf, PAGE_SIZE, "%s\n", (char *)eattr->var);
+ return sysfs_emit(buf, "%s\n", (char *)eattr->var);
}

static ssize_t cci_pmu_event_show(struct device *dev,
@@ -705,8 +705,7 @@ static ssize_t cci_pmu_event_show(struct device *dev,
struct dev_ext_attribute *eattr = container_of(attr,
struct dev_ext_attribute, attr);
/* source parameter is mandatory for normal PMU events */
- return snprintf(buf, PAGE_SIZE, "source=?,event=0x%lx\n",
- (unsigned long)eattr->var);
+ return sysfs_emit(buf, "source=?,event=0x%lx\n", (unsigned long)eattr->var);
}

static int pmu_is_valid_counter(struct cci_pmu *cci_pmu, int idx)
--
1.8.3.1


2021-02-05 00:12:36

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH] drivers/perf: convert sysfs sprintf/snprintf family to sysfs_emit

On Thu, Feb 04, 2021 at 11:32:51AM +0800, Jiapeng Chong wrote:
> Fix the following coccicheck warning:
>
> ./drivers/perf/arm-cci.c:708:8-16: WARNING: use scnprintf or sprintf.
> ./drivers/perf/arm-cci.c:699:8-16: WARNING: use scnprintf or sprintf.
> ./drivers/perf/arm-cci.c:528:8-16: WARNING: use scnprintf or sprintf.
> ./drivers/perf/arm-cci.c:309:8-16: WARNING: use scnprintf or sprintf.
>
> Reported-by: Abaci Robot<[email protected]>
> Signed-off-by: Jiapeng Chong <[email protected]>
> ---
> drivers/perf/arm-cci.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)

Looks like the same issue exists for other drivers under drivers/perf/. How
about fixing them all together?

Will