[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20211108091200.103745-1-ye.guojin@zte.com.cn>
Date: Mon, 8 Nov 2021 09:12:00 +0000
From: cgel.zte@...il.com
To: tglx@...utronix.de
Cc: peterz@...radead.org, vincent.donnefort@....com,
valentin.schneider@....com, mingo@...nel.org, npiggin@...il.com,
rdunlap@...radead.org, yuehaibing@...wei.com, ye.guojin@....com.cn,
linux-kernel@...r.kernel.org, Zeal Robot <zealci@....com.cn>
Subject: [PATCH] cpu/hotplug: replace snprintf and sprintf in show functions with sysfs_emit
From: Ye Guojin <ye.guojin@....com.cn>
coccicheck complains about the use of snprintf() in sysfs show
functions:
WARNING use scnprintf or sprintf
Use sysfs_emit or sysfs_emit_at instead of snprintf or sprintf makes
more sense.
Reported-by: Zeal Robot <zealci@....com.cn>
Signed-off-by: Ye Guojin <ye.guojin@....com.cn>
---
kernel/cpu.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index fffe8b738201..fcaac665c53e 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -2261,7 +2261,7 @@ static ssize_t state_show(struct device *dev,
{
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
- return sprintf(buf, "%d\n", st->state);
+ return sysfs_emit(buf, "%d\n", st->state);
}
static DEVICE_ATTR_RO(state);
@@ -2309,7 +2309,7 @@ static ssize_t target_show(struct device *dev,
{
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
- return sprintf(buf, "%d\n", st->target);
+ return sysfs_emit(buf, "%d\n", st->target);
}
static DEVICE_ATTR_RW(target);
@@ -2368,7 +2368,7 @@ static ssize_t fail_show(struct device *dev,
{
struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, dev->id);
- return sprintf(buf, "%d\n", st->fail);
+ return sysfs_emit(buf, "%d\n", st->fail);
}
static DEVICE_ATTR_RW(fail);
@@ -2397,8 +2397,7 @@ static ssize_t states_show(struct device *dev,
struct cpuhp_step *sp = cpuhp_get_step(i);
if (sp->name) {
- cur = sprintf(buf, "%3d: %s\n", i, sp->name);
- buf += cur;
+ cur = sysfs_emit_at(buf, res, "%3d: %s\n", i, sp->name);
res += cur;
}
}
@@ -2481,9 +2480,7 @@ static const char *smt_states[] = {
static ssize_t control_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- const char *state = smt_states[cpu_smt_control];
-
- return snprintf(buf, PAGE_SIZE - 2, "%s\n", state);
+ return sysfs_emit(buf, "%s\n", smt_states[cpu_smt_control]);
}
static ssize_t control_store(struct device *dev, struct device_attribute *attr,
@@ -2496,7 +2493,7 @@ static DEVICE_ATTR_RW(control);
static ssize_t active_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- return snprintf(buf, PAGE_SIZE - 2, "%d\n", sched_smt_active());
+ return sysfs_emit(buf, "%d\n", sched_smt_active());
}
static DEVICE_ATTR_RO(active);
--
2.25.1
Powered by blists - more mailing lists