x86/microcode/amd: Fix snprintf() format string warning in W=1 build
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 16 Oct 2023 22:48:58 +0000 (18:48 -0400)
committerBorislav Petkov (AMD) <bp@alien8.de>
Tue, 17 Oct 2023 21:51:58 +0000 (23:51 +0200)
commit2e9064faccd1a5b9de8c6f4b23d9f4948901cbe9
tree9a7e3f1f7c73ee83030e0baf33c70cd9021e1840
parent58720809f52779dc0f08e53e54b014209d13eebb
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
arch/x86/kernel/cpu/microcode/amd.c