x86/cpu: amd: fix warning in W=1 build
Subsystems (2)
PATCH 1/1 x86/cpu: amd: fix warning in W=1 build
Building with GCC 11.x results in the following warning:
arch/x86/kernel/cpu/microcode/amd.c: In function ‘find_blobs_in_containers’:arch/x86/kernel/cpu/microcode/amd.c:504:58: error: ‘h.bin’ directive output may be truncated writing 5 bytes into a region of size between 1 and 7 [-Werror=format-truncation=] arch/x86/kernel/cpu/microcode/amd.c:503:17: note: ‘snprintf’ output between 35 and 41 bytes into a destination of size 36
The issue is that GCC does not know that the family can only be a byte (it ultimately comes from CPUID). Suggest the right size to the compiler by marking the argument as char-size ("hh"). While at it, instead of using the slightly more obscure precision specifier use the width with zero padding (over 23000 occurrences in kernel sources, vs 500 for the idiom using the precision).
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -501,7 +501,7 @@ static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)if (family >=0x15 )snprintf (fw_name,sizeof (fw_name), -"amd-ucode/microcode_amd_fam%.2xh.bin" , family); +"amd-ucode/microcode_amd_fam%02hhxh.bin" , family);if (firmware_request_builtin (&fw, fw_name)) { cp->size = fw.size;
Signature · 1 line
2.39.1
[tip: x86/microcode] x86/microcode/amd: Fix snprintf() format string warning in W=1 build
The following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: 41a3e409e3e69892e9884b16b2fb6925e726f511 Gitweb: https://git.kernel.org/tip/41a3e409e3e69892e9884b16b2fb6925e726f511 Author: Paolo Bonzini <[email protected]> AuthorDate: Mon, 16 Oct 2023 18:48:58 -04:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Tue, 17 Oct 2023 13:22:26 +02:00
x86/microcode/amd: Fix snprintf() format string warning in W=1 build
Building with GCC 11.x results in the following warning:
arch/x86/kernel/cpu/microcode/amd.c: In function ‘find_blobs_in_containers’:
arch/x86/kernel/cpu/microcode/amd.c:504:58: error: ‘h.bin’ directive output may be truncated writing 5 bytes into a region of size between 1 and 7 [-Werror=format-truncation=] arch/x86/kernel/cpu/microcode/amd.c:503:17: note: ‘snprintf’ output between 35 and 41 bytes into a destination of size 36
The issue is that GCC does not know that the family can only be a byte (it ultimately comes from CPUID). Suggest the right size to the compiler by marking the argument as char-size ("hh"). While at it, instead of using the slightly more obscure precision specifier use the width with zero padding (over 23000 occurrences in kernel sources, vs 500 for the idiom using the precision).
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -485,7 +485,7 @@ static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)if (family >=0x15 )snprintf (fw_name,sizeof (fw_name), -"amd-ucode/microcode_amd_fam%.2xh.bin" , family); +"amd-ucode/microcode_amd_fam%02hhxh.bin" , family);if (firmware_request_builtin (&fw, fw_name)) { cp->size = fw.size;
[tip: x86/microcode] x86/microcode/amd: Fix snprintf() format string warning in W=1 build
In reply to Paolo BonziniThe following commit has been merged into the x86/microcode branch of tip:
The following commit has been merged into the x86/microcode branch of tip:
Commit-ID: 2e9064faccd1a5b9de8c6f4b23d9f4948901cbe9 Gitweb: https://git.kernel.org/tip/2e9064faccd1a5b9de8c6f4b23d9f4948901cbe9 Author: Paolo Bonzini <[email protected]> AuthorDate: Mon, 16 Oct 2023 18:48:58 -04:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 17 Oct 2023 23:51:58 +02:00
x86/microcode/amd: Fix snprintf() format string warning in W=1 build
Building with GCC 11.x results in the following warning:
arch/x86/kernel/cpu/microcode/amd.c: In function ‘find_blobs_in_containers’:
arch/x86/kernel/cpu/microcode/amd.c:504:58: error: ‘h.bin’ directive output may be truncated writing 5 bytes into a region of size between 1 and 7 [-Werror=format-truncation=] arch/x86/kernel/cpu/microcode/amd.c:503:17: note: ‘snprintf’ output between 35 and 41 bytes into a destination of size 36
The issue is that GCC does not know that the family can only be a byte (it ultimately comes from CPUID). Suggest the right size to the compiler by marking the argument as char-size ("hh"). While at it, instead of using the slightly more obscure precision specifier use the width with zero padding (over 23000 occurrences in kernel sources, vs 500 for the idiom using the precision).
--- arch/x86/kernel/cpu/microcode/amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/amd.c +1 -1
@@ -501,7 +501,7 @@ static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)if (family >=0x15 )snprintf (fw_name,sizeof (fw_name), -"amd-ucode/microcode_amd_fam%.2xh.bin" , family); +"amd-ucode/microcode_amd_fam%02hhxh.bin" , family);if (firmware_request_builtin (&fw, fw_name)) { cp->size = fw.size;