[PATCH] kernel: events: replace snprintf in show functions with sysfs_emit

From: cgel . zte
Date: Wed Nov 03 2021 - 04:24:31 EST


From: Jing Yao <yao.jing2@xxxxxxxxxx>

coccicheck complains about the use of snprintf() in sysfs show
functions:
WARNING use scnprintf or sprintf

Use sysfs_emit instead of scnprintf or sprintf make more sense.

Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
Signed-off-by: Jing Yao <yao.jing2@xxxxxxxxxx>
---
kernel/events/core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index f2253ea729a2..15419ced2a51 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -10921,7 +10921,7 @@ static ssize_t nr_addr_filters_show(struct device *dev,
{
struct pmu *pmu = dev_get_drvdata(dev);

- return snprintf(page, PAGE_SIZE - 1, "%d\n", pmu->nr_addr_filters);
+ return sysfs_emit(page, "%d\n", pmu->nr_addr_filters);
}
DEVICE_ATTR_RO(nr_addr_filters);

@@ -10932,7 +10932,7 @@ type_show(struct device *dev, struct device_attribute *attr, char *page)
{
struct pmu *pmu = dev_get_drvdata(dev);

- return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->type);
+ return sysfs_emit(page, "%d\n", pmu->type);
}
static DEVICE_ATTR_RO(type);

@@ -10943,7 +10943,7 @@ perf_event_mux_interval_ms_show(struct device *dev,
{
struct pmu *pmu = dev_get_drvdata(dev);

- return snprintf(page, PAGE_SIZE-1, "%d\n", pmu->hrtimer_interval_ms);
+ return sysfs_emit(page, "%d\n", pmu->hrtimer_interval_ms);
}

static DEFINE_MUTEX(mux_interval_mutex);
--
2.25.1