Skip to contentSkip to conversation

ARM: sharpsl_param: work around -Wstringop-overread warning

PATCH RESEND Applied Arnd Bergmann 3 participants 3 messages Sep 27, 2021 – Oct 5, 2021 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 ARM: sharpsl_param: work around -Wstringop-overread warning

From: Arnd Bergmann <[email protected]>

gcc warns that accessing a pointer based on a numeric constant may be an offset into a NULL pointer, and would therefore has zero accessible bytes:

arch/arm/common/sharpsl_param.c: In function ‘sharpsl_save_param’:
arch/arm/common/sharpsl_param.c:43:9: error: ‘memcpy’ reading 64 bytes from a region of size 0 [-Werror=stringop-overread]

   43 |         memcpy(&sharpsl_param, param_start(PARAM_BASE), sizeof(struct sharpsl_param_info));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In this particular case, the warning is bogus since this is the actual pointer, not an offset on a NULL pointer. Add a local variable to shut up the warning and hope it doesn't come back.

---
If there are no objections, I'd apply this one through the soc tree.

---
 arch/arm/common/sharpsl_param.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/common/sharpsl_param.c +3 -1
index efeb5724d9e9..6237ede2f0c7 100644
@@ -40,7 +40,9 @@ EXPORT_SYMBOL(sharpsl_param);
 
 void sharpsl_save_param(void)
 {
-	memcpy(&sharpsl_param, param_start(PARAM_BASE), sizeof(struct sharpsl_param_info));
+	struct sharpsl_param_info *params = param_start(PARAM_BASE);
+
+	memcpy(&sharpsl_param, params, sizeof(*params));
 
 	if (sharpsl_param.comadj_keyword != COMADJ_MAGIC)
 		sharpsl_param.comadj=-1;
Signature · 1 line
2.29.2
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

gcc warns that accessing a pointer based on a numeric constant may be an offset into a NULL pointer, and would therefore has zero accessible bytes:

arch/arm/common/sharpsl_param.c: In function ‘sharpsl_save_param’:
arch/arm/common/sharpsl_param.c:43:9: error: ‘memcpy’ reading 64 bytes from a region of size 0 [-Werror=stringop-overread]

Quoted 8 lines
   43 |         memcpy(&sharpsl_param, param_start(PARAM_BASE), sizeof(struct sharpsl_param_info));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In this particular case, the warning is bogus since this is the actual pointer, not an offset on a NULL pointer. Add a local variable to shut up the warning and hope it doesn't come back.

Quoted 17 lines
Cc Haojian Zhuang <[email protected]>
Cc Robert Jarzmik <[email protected]>
Cc Russell King <[email protected]>
Cc Linus Walleij <[email protected]>

---
If there are no objections, I'd apply this one through the soc tree.

---
 arch/arm/common/sharpsl_param.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/common/sharpsl_param.c +0 -0
index efeb5724d9e9..6237ede2f0c7 100644

arch/arm/common/sharpsl_param.c EXPORT_SYMBOL(sharpsl_param); · line 48

Quoted 10 lines
arch/arm/common/sharpsl_param.c +3 -1
@@ -40,7 +40,9 @@ EXPORT_SYMBOL(sharpsl_param);
 
 void sharpsl_save_param(void)
 {
-	memcpy(&sharpsl_param, param_start(PARAM_BASE), sizeof(struct sharpsl_param_info));
+	struct sharpsl_param_info *params = param_start(PARAM_BASE);
+
+	memcpy(&sharpsl_param, params, sizeof(*params));
 
 	if (sharpsl_param.comadj_keyword != COMADJ_MAGIC)
 		sharpsl_param.comadj=-1;

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw
In reply to Arnd Bergmann
This patch was applied to soc/soc.git (refs/heads/arm/fixes):

Hello:

This patch was applied to soc/soc.git (refs/heads/arm/fixes):

Quoted 6 lines · On Mon, 27 Sep 2021 16:53:25 +0200 you wrote:

From: Arnd Bergmann <[email protected]>

gcc warns that accessing a pointer based on a numeric constant may be an offset into a NULL pointer, and would therefore has zero accessible bytes:

Quoted 6 lines

arch/arm/common/sharpsl_param.c: In function ‘sharpsl_save_param’:
arch/arm/common/sharpsl_param.c:43:9: error: ‘memcpy’ reading 64 bytes from a region of size 0 [-Werror=stringop-overread]

   43 |         memcpy(&sharpsl_param, param_start(PARAM_BASE), sizeof(struct sharpsl_param_info));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[...]

Here is the summary with links:
- [RESEND] ARM: sharpsl_param: work around -Wstringop-overread warning

    https://git.kernel.org/soc/soc/c/34186b48d29b

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html