Replace raw sprintf() and manual buffer arithmetic with sysfs_emit_at(),
which bounds output to PAGE_SIZE.
Signed-off-by: Bradley Morgan <include@grrlz.net>
---
kernel/cpu.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index f975bb34915b..25d88cf2bb15 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -2857,18 +2857,15 @@ static const struct attribute_group cpuhp_cpu_attr_group = {
static ssize_t states_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- ssize_t cur, res = 0;
+ ssize_t res = 0;
int i;
mutex_lock(&cpuhp_state_mutex);
for (i = CPUHP_OFFLINE; i <= CPUHP_ONLINE; i++) {
struct cpuhp_step *sp = cpuhp_get_step(i);
- if (sp->name) {
- cur = sprintf(buf, "%3d: %s\n", i, sp->name);
- buf += cur;
- res += cur;
- }
+ if (sp->name)
+ res += sysfs_emit_at(buf, res, "%3d: %s\n", i, sp->name);
}
mutex_unlock(&cpuhp_state_mutex);
return res;
--
2.53.0