Skip to content

Commit 2e9064f

Browse files
bonzinibp3tk0v
authored andcommitted
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). Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Closes: https://lore.kernel.org/oe-kbuild-all/202308252255.2HPJ6x5Q-lkp@intel.com/ Link: https://lore.kernel.org/r/20231016224858.2829248-1-pbonzini@redhat.com
1 parent 5872080 commit 2e9064f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • arch/x86/kernel/cpu/microcode

arch/x86/kernel/cpu/microcode/amd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)
501501

502502
if (family >= 0x15)
503503
snprintf(fw_name, sizeof(fw_name),
504-
"amd-ucode/microcode_amd_fam%.2xh.bin", family);
504+
"amd-ucode/microcode_amd_fam%02hhxh.bin", family);
505505

506506
if (firmware_request_builtin(&fw, fw_name)) {
507507
cp->size = fw.size;

0 commit comments

Comments
 (0)