mirror of
https://github.com/torvalds/linux.git
synced 2026-11-23 23:11:40 +00:00
powerpc/papr_scm: Return the string length from the sysfs show functions
perf_stats_show() and flags_show() build their output with a seq_buf and return seq_buf_used(), which may include the trailing NUL byte when the seq_buf has overflowed. Use seq_buf_strlen() instead. As suggested in review, use it as well for flags_show()'s check whether any flag was printed. Build tested ARCH=powerpc ppc64_defconfig with GCC powerpc64-linux-gnu 16.2.0: arch/powerpc/platforms/pseries/papr_scm.o Assisted-by: LLM Reviewed-by: Andy Shevchenko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Kees Cook <[email protected]>
This commit is contained in:
@@ -1108,7 +1108,7 @@ static ssize_t perf_stats_show(struct device *dev,
|
||||
|
||||
free_stats:
|
||||
kfree(stats);
|
||||
return rc ? rc : (ssize_t)seq_buf_used(&s);
|
||||
return rc ?: (ssize_t)seq_buf_strlen(&s);
|
||||
}
|
||||
static DEVICE_ATTR_ADMIN_RO(perf_stats);
|
||||
|
||||
@@ -1147,10 +1147,10 @@ static ssize_t flags_show(struct device *dev,
|
||||
if (health & PAPR_PMEM_SCRUBBED_AND_LOCKED)
|
||||
seq_buf_printf(&s, "scrubbed locked ");
|
||||
|
||||
if (seq_buf_used(&s))
|
||||
if (seq_buf_strlen(&s))
|
||||
seq_buf_printf(&s, "\n");
|
||||
|
||||
return seq_buf_used(&s);
|
||||
return seq_buf_strlen(&s);
|
||||
}
|
||||
DEVICE_ATTR_RO(flags);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user