Skip to contentSkip to conversation

powerpc/ps3: Fix repository.c build failure

PATCH Applied Thorsten Blum 3 participants 7 messages Jul 3 – Sep 9

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/ps3: Fix repository.c build failure

GCC fails to build ps3_defconfig with the following errors:

arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 3 [-Werror=stringop-overread]

     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
  arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 4 [-Werror=stringop-overread]
     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The current use of strnlen(text, sizeof(n)) triggers -Wstringop-overread when text is a short string literal that is smaller than sizeof(n), such as "bi" or "bus". Use strlen(text) instead and clamp the copy length to sizeof(n) before memcpy().

Drop the redundant char * cast while at it.

Fixes f94a84a09148 ("powerpc/ps3: refactor strncpy usage")
---
 arch/powerpc/platforms/ps3/repository.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/platforms/ps3/repository.c +4 -1
index b8c030eab138..0cc755ac3e7f 100644
@@ -6,6 +6,8 @@
  *  Copyright 2006 Sony Corp.
  */
 
+#include <linux/minmax.h>
+
 #include <asm/lv1call.h>
 
 #include "platform.h"
@@ -74,8 +76,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
 static u64 make_first_field(const char *text, u64 index)
 {
 	u64 n = 0;
+	size_t len = min(strlen(text), sizeof(n));
 
-	memcpy((char *)&n, text, strnlen(text, sizeof(n)));
+	memcpy(&n, text, len);
 	return PS3_VENDOR_ID_NONE + (n >> 32) + index;
 }
 
#1 lore raw
Quoted 39 lines · Thorsten Blum

GCC fails to build ps3_defconfig with the following errors:

arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 3 [-Werror=stringop-overread]

     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
  arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 4 [-Werror=stringop-overread]
     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The current use of strnlen(text, sizeof(n)) triggers -Wstringop-overread when text is a short string literal that is smaller than sizeof(n), such as "bi" or "bus". Use strlen(text) instead and clamp the copy length to sizeof(n) before memcpy().

Drop the redundant char * cast while at it.

Fixes f94a84a09148 ("powerpc/ps3: refactor strncpy usage")
---
 arch/powerpc/platforms/ps3/repository.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/platforms/ps3/repository.c +2 -0
index b8c030eab138..0cc755ac3e7f 100644
@@ -6,6 +6,8 @@
  *  Copyright 2006 Sony Corp.
  */
 
+#include <linux/minmax.h>
+
 #include <asm/lv1call.h>
 
 #include "platform.h"

arch/powerpc/platforms/ps3/repository.c static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4, · line 84

Quoted 10 lines
arch/powerpc/platforms/ps3/repository.c +2 -1
@@ -74,8 +76,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
 static u64 make_first_field(const char *text, u64 index)
 {
 	u64 n = 0;
+	size_t len = min(strlen(text), sizeof(n));
 
-	memcpy((char *)&n, text, strnlen(text, sizeof(n)));
+	memcpy(&n, text, len);
 	return PS3_VENDOR_ID_NONE + (n >> 32) + index;
 }
 

Gentle ping.

Thanks,
Thorsten

#2 lore raw
Quoted 53 lines · Thorsten Blum
Quoted 39 lines · Thorsten Blum

GCC fails to build ps3_defconfig with the following errors:

arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 3 [-Werror=stringop-overread]

     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
  arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 4 [-Werror=stringop-overread]
     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The current use of strnlen(text, sizeof(n)) triggers -Wstringop-overread when text is a short string literal that is smaller than sizeof(n), such as "bi" or "bus". Use strlen(text) instead and clamp the copy length to sizeof(n) before memcpy().

Drop the redundant char * cast while at it.

Fixes f94a84a09148 ("powerpc/ps3: refactor strncpy usage")
---
 arch/powerpc/platforms/ps3/repository.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/platforms/ps3/repository.c +2 -0
index b8c030eab138..0cc755ac3e7f 100644
@@ -6,6 +6,8 @@
  *  Copyright 2006 Sony Corp.
  */
 
+#include <linux/minmax.h>
+
 #include <asm/lv1call.h>
 
 #include "platform.h"

arch/powerpc/platforms/ps3/repository.c static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4, · line 84

Quoted 10 lines
arch/powerpc/platforms/ps3/repository.c +2 -1
@@ -74,8 +76,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
 static u64 make_first_field(const char *text, u64 index)
 {
 	u64 n = 0;
+	size_t len = min(strlen(text), sizeof(n));
 
-	memcpy((char *)&n, text, strnlen(text, sizeof(n)));
+	memcpy(&n, text, len);
 	return PS3_VENDOR_ID_NONE + (n >> 32) + index;
 }
 

Gentle ping.

Quoted 2 lines

Thanks,
Thorsten

Interestingly, GCC 14.2.0 and Clang 22.1.8 don't report an error, whereas GCC 16.1.1 does.

#3 lore raw
In reply to Thorsten Blum

Le 03/07/2026 à 18:58, Thorsten Blum a écrit :

Quoted 39 lines

GCC fails to build ps3_defconfig with the following errors:

arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:

   arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 3 [-Werror=stringop-overread]
      78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
   arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 4 [-Werror=stringop-overread]
      78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The current use of strnlen(text, sizeof(n)) triggers -Wstringop-overread when text is a short string literal that is smaller than sizeof(n), such as "bi" or "bus". Use strlen(text) instead and clamp the copy length to sizeof(n) before memcpy().

Drop the redundant char * cast while at it.

Fixes f94a84a09148 ("powerpc/ps3: refactor strncpy usage")
---
  arch/powerpc/platforms/ps3/repository.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/platforms/ps3/repository.c +2 -0
index b8c030eab138..0cc755ac3e7f 100644
@@ -6,6 +6,8 @@
   *  Copyright 2006 Sony Corp.
   */
 
+#include <linux/minmax.h>
+
  #include <asm/lv1call.h>
 
  #include "platform.h"

arch/powerpc/platforms/ps3/repository.c static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4, · line 84

Quoted 10 lines
arch/powerpc/platforms/ps3/repository.c +2 -1
@@ -74,8 +76,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
  static u64 make_first_field(const char *text, u64 index)
  {
  	u64 n = 0;
+	size_t len = min(strlen(text), sizeof(n));
 
-	memcpy((char *)&n, text, strnlen(text, sizeof(n)));
+	memcpy(&n, text, len);
  	return PS3_VENDOR_ID_NONE + (n >> 32) + index;
  }
 

Maybe change to u32 and remove the n >> 32.

Shouldn't the same fix be done in make_field() ?

Christophe

#4 lore raw
Quoted 49 lines · Christophe Leroy (CS GROUP)

Le 03/07/2026 à 18:58, Thorsten Blum a écrit :

Quoted 37 lines

GCC fails to build ps3_defconfig with the following errors:

arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:

   arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 3 [-Werror=stringop-overread]
      78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
   arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 4 [-Werror=stringop-overread]
      78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The current use of strnlen(text, sizeof(n)) triggers -Wstringop-overread when text is a short string literal that is smaller than sizeof(n), such as "bi" or "bus". Use strlen(text) instead and clamp the copy length to sizeof(n) before memcpy().

Drop the redundant char * cast while at it.

Fixes f94a84a09148 ("powerpc/ps3: refactor strncpy usage")
---
  arch/powerpc/platforms/ps3/repository.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/platforms/ps3/repository.c +2 -0
index b8c030eab138..0cc755ac3e7f 100644
@@ -6,6 +6,8 @@
   *  Copyright 2006 Sony Corp.
   */
+#include <linux/minmax.h>
+
  #include <asm/lv1call.h>
  #include "platform.h"

arch/powerpc/platforms/ps3/repository.c static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4, · line 82

Quoted 8 lines
arch/powerpc/platforms/ps3/repository.c +2 -1
@@ -74,8 +76,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
  static u64 make_first_field(const char *text, u64 index)
  {
  	u64 n = 0;
+	size_t len = min(strlen(text), sizeof(n));
-	memcpy((char *)&n, text, strnlen(text, sizeof(n)));
+	memcpy(&n, text, len);
  	return PS3_VENDOR_ID_NONE + (n >> 32) + index;
  }

Maybe change to u32 and remove the n >> 32.

Quoted 1 line

Shouldn't the same fix be done in make_field() ?

make_field() has two callers where the compiler can't infer the size of the string at compile time, so it doesn't produce this error.

make_first_field() is called only with constant strings, which lets the compiler infer that all string lengths are less than 8 bytes.

#5 lore raw
In reply to Thorsten Blum
Quoted 39 lines · Thorsten Blum

GCC fails to build ps3_defconfig with the following errors:

arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 3 [-Werror=stringop-overread]

     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
  arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 4 [-Werror=stringop-overread]
     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The current use of strnlen(text, sizeof(n)) triggers -Wstringop-overread when text is a short string literal that is smaller than sizeof(n), such as "bi" or "bus". Use strlen(text) instead and clamp the copy length to sizeof(n) before memcpy().

Drop the redundant char * cast while at it.

Fixes f94a84a09148 ("powerpc/ps3: refactor strncpy usage")
---
 arch/powerpc/platforms/ps3/repository.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/platforms/ps3/repository.c +2 -0
index b8c030eab138..0cc755ac3e7f 100644
@@ -6,6 +6,8 @@
  *  Copyright 2006 Sony Corp.
  */
 
+#include <linux/minmax.h>
+
 #include <asm/lv1call.h>
 
 #include "platform.h"

arch/powerpc/platforms/ps3/repository.c static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4, · line 84

Quoted 10 lines
arch/powerpc/platforms/ps3/repository.c +2 -1
@@ -74,8 +76,9 @@ static void _dump_node(unsigned int lpar_id, u64 n1, u64 n2, u64 n3, u64 n4,
 static u64 make_first_field(const char *text, u64 index)
 {
 	u64 n = 0;
+	size_t len = min(strlen(text), sizeof(n));
 
-	memcpy((char *)&n, text, strnlen(text, sizeof(n)));
+	memcpy(&n, text, len);
 	return PS3_VENDOR_ID_NONE + (n >> 32) + index;
 }
 

Gentle ping - it's been a few weeks and the build failure is still present. Is the approach here ok or would you prefer something else?

Thanks,
Thorsten

maintainer Applied
#6 lore raw
In reply to Thorsten Blum
Quoted 4 lines · Thorsten Blum

GCC fails to build ps3_defconfig with the following errors:

arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 3 [-Werror=stringop-overread]

Quoted 8 lines
     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  arch/powerpc/platforms/ps3/repository.c: In function ‘make_first_field.constprop’:
  arch/powerpc/platforms/ps3/repository.c:78:9: error: ‘strnlen’ specified bound 8 exceeds source size 4 [-Werror=stringop-overread]
     78 |         memcpy((char *)&n, text, strnlen(text, sizeof(n)));
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[...]

Applied to powerpc/fixes.

[1/1] powerpc/ps3: Fix repository.c build failure

      https://git.kernel.org/powerpc/c/5ba79d37403d86082ab4083b0f51ec3008a942cb

cheers