[PATCH v3 09/11] powerpc/papr_scm: Return the string length from the sysfs show functions

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

COOLING14d SUPERSEDED: 8 (8M)

Revision v3 of 4 in this series; 1 review trailer.

3 messages, 2 authors, 14d ago · open the first message on its own page

[PATCH v3 09/11] powerpc/papr_scm: Return the string length from the sysfs show functions

From: Kees Cook <kees@kernel.org>
Date: 2026-09-30 23:52:53

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.

Build tested ARCH=powerpc ppc64_defconfig with GCC powerpc64-linux-gnu
16.1.0:
arch/powerpc/platforms/pseries/papr_scm.o

Assisted-by: LLM
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Kees Cook <kees@kernel.org>
---
 arch/powerpc/platforms/pseries/papr_scm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 75da96c08cdd..b03cfd8528f5 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -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);
 
@@ -1150,7 +1150,7 @@ static ssize_t flags_show(struct device *dev,
 	if (seq_buf_used(&s))
 		seq_buf_printf(&s, "\n");
 
-	return seq_buf_used(&s);
+	return seq_buf_strlen(&s);
 }
 DEVICE_ATTR_RO(flags);
 
-- 
2.34.1

Re: [PATCH v3 09/11] powerpc/papr_scm: Return the string length from the sysfs show functions

From: Madhavan Srinivasan <maddy@linux.ibm.com>
Date: 2026-10-01 04:18:22

On 10/1/26 5:22 AM, Kees Cook wrote:
quoted hunk
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.

Build tested ARCH=powerpc ppc64_defconfig with GCC powerpc64-linux-gnu
16.1.0:
arch/powerpc/platforms/pseries/papr_scm.o

Assisted-by: LLM
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Kees Cook <kees@kernel.org>
---
  arch/powerpc/platforms/pseries/papr_scm.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 75da96c08cdd..b03cfd8528f5 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -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);
  
@@ -1150,7 +1150,7 @@ static ssize_t flags_show(struct device *dev,
  	if (seq_buf_used(&s))
this can also be seq_buf_strlen instead
quoted hunk
  		seq_buf_printf(&s, "\n");
  
-	return seq_buf_used(&s);
+	return seq_buf_strlen(&s);
  }
  DEVICE_ATTR_RO(flags);
  

Re: [PATCH v3 09/11] powerpc/papr_scm: Return the string length from the sysfs show functions

From: Kees Cook <kees@kernel.org>
Date: 2026-10-02 07:54:09

On Thu, Oct 01, 2026 at 09:47:56AM +0530, Madhavan Srinivasan wrote:
On 10/1/26 5:22 AM, Kees Cook wrote:
quoted
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.

Build tested ARCH=powerpc ppc64_defconfig with GCC powerpc64-linux-gnu
16.1.0:
arch/powerpc/platforms/pseries/papr_scm.o

Assisted-by: LLM
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Kees Cook <kees@kernel.org>
---
  arch/powerpc/platforms/pseries/papr_scm.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 75da96c08cdd..b03cfd8528f5 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -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);
@@ -1150,7 +1150,7 @@ static ssize_t flags_show(struct device *dev,
  	if (seq_buf_used(&s))
this can also be seq_buf_strlen instead
It could be, yeah. I left it because it seemed be more about "did we
touch this at all?" But it's honestly all the same. I will respin with
it changed too.
quoted
  		seq_buf_printf(&s, "\n");
-	return seq_buf_used(&s);
+	return seq_buf_strlen(&s);
  }
  DEVICE_ATTR_RO(flags);
-- 
Kees Cook
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help