Skip to contentSkip to conversation

x86/mce/dev-mcelog: Fix "make W=1" warning about strncpy

PATCH Applied Tony Luck 2 participants 2 messages May 27, 2020

Subsystems (2)
lore
Share & tools
lore

Tony Luck

author maintainer
#0 lore raw

PATCH 1/1 x86/mce/dev-mcelog: Fix "make W=1" warning about strncpy

The kbuild test robot reported this warning:

arch/x86/kernel/cpu/mce/dev-mcelog.c: In function 'dev_mcelog_init_device':
arch/x86/kernel/cpu/mce/dev-mcelog.c:346:2: warning: 'strncpy' output truncated before terminating nul copying 12 bytes from a string of the same length [-Wstringop-truncation]

This is accurate, but I don't care that the trailing NUL character isn't copied. The string being copied is just a magic number signature so that crash dump tools can be sure they are decoding the right blob of memory.

Change to use memcpy() instead of strncpy()

---
 arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/dev-mcelog.c +1 -1
index d089567a9ce8..bcb379b2fd42 100644
@@ -343,7 +343,7 @@ static __init int dev_mcelog_init_device(void)
 	if (!mcelog)
 		return -ENOMEM;
 
-	strncpy(mcelog->signature, MCE_LOG_SIGNATURE, sizeof(mcelog->signature));
+	memcpy(mcelog->signature, MCE_LOG_SIGNATURE, sizeof(mcelog->signature));
 	mcelog->len = mce_log_len;
 	mcelog->recordlen = sizeof(struct mce);
 
Signature · 1 line
2.21.1
merge bot Applied
#1 lore raw

[tip: ras/core] x86/mce/dev-mcelog: Fix -Wstringop-truncation warning about strncpy()

The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     45811ba140593e288a288c2a2e45d25f38d20d73
Gitweb:        https://git.kernel.org/tip/45811ba140593e288a288c2a2e45d25f38d20d73
Author:        Tony Luck <[email protected]>
AuthorDate:    Wed, 27 May 2020 11:28:08 -07:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Wed, 27 May 2020 21:19:38 +02:00

x86/mce/dev-mcelog: Fix -Wstringop-truncation warning about strncpy()

The kbuild test robot reported this warning:

  arch/x86/kernel/cpu/mce/dev-mcelog.c: In function 'dev_mcelog_init_device':
  arch/x86/kernel/cpu/mce/dev-mcelog.c:346:2: warning: 'strncpy' output \
    truncated before terminating nul copying 12 bytes from a string of the \
    same length [-Wstringop-truncation]

This is accurate, but I don't care that the trailing NUL character isn't copied. The string being copied is just a magic number signature so that crash dump tools can be sure they are decoding the right blob of memory.

Use memcpy() instead of strncpy().

Fixes d8ecca4043f2 ("x86/mce/dev-mcelog: Dynamically allocate space for machine check records")
---
 arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/dev-mcelog.c +1 -1
index a4fd528..43c4660 100644
@@ -349,7 +349,7 @@ static __init int dev_mcelog_init_device(void)
 	if (!mcelog)
 		return -ENOMEM;
 
-	strncpy(mcelog->signature, MCE_LOG_SIGNATURE, sizeof(mcelog->signature));
+	memcpy(mcelog->signature, MCE_LOG_SIGNATURE, sizeof(mcelog->signature));
 	mcelog->len = mce_log_len;
 	mcelog->recordlen = sizeof(struct mce);