lkml.org 
[lkml]   [2021]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] cpu/hotplug: replace snprintf and sprintf in show functions with sysfs_emit
Date
From: Ye Guojin <ye.guojin@zte.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@zte.com.cn>
Signed-off-by: Ye Guojin <ye.guojin@zte.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
\
 
 \ /
  Last update: 2021-11-08 10:13    [W:0.043 / U:0.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site