The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] x86: microcode: avoid -Wformat warning with clang-15
@ 2024-04-05 20:49 Arnd Bergmann
  2024-04-05 21:51 ` [tip: x86/microcode] x86/microcode/AMD: Avoid " tip-bot2 for Arnd Bergmann
  2024-04-05 21:55 ` [PATCH] x86: microcode: avoid " Justin Stitt
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2024-04-05 20:49 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Arnd Bergmann, Thomas Gleixner, Ingo Molnar, Dave Hansen, x86,
	H. Peter Anvin, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, Ashok Raj, Nathan Fontenot,
	Paolo Bonzini, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

Older versions of clang show a warning for amd.c after a fix for a gcc
warning:

arch/x86/kernel/cpu/microcode/amd.c:478:47: error: format specifies type 'unsigned char' but the argument has type 'u16' (aka 'unsigned short') [-Werror,-Wformat]
                         "amd-ucode/microcode_amd_fam%02hhxh.bin", family);
                                                     ~~~~~~        ^~~~~~
                                                     %02hx

In clang-16 and higher, this warning is disabled by default, but clang-15 is
still supported, and it's trivial to avoid by adapting the types according
to the range of the passed data and the format string.

Fixes: 2e9064faccd1 ("x86/microcode/amd: Fix snprintf() format string warning in W=1 build")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/x86/kernel/cpu/microcode/amd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 13b45b9c806d..620f0af713ca 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -465,7 +465,7 @@ static bool early_apply_microcode(u32 cpuid_1_eax, u32 old_rev, void *ucode, siz
 	return !__apply_microcode_amd(mc);
 }
 
-static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)
+static bool get_builtin_microcode(struct cpio_data *cp, u8 family)
 {
 	char fw_name[36] = "amd-ucode/microcode_amd.bin";
 	struct firmware fw;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [tip: x86/microcode] x86/microcode/AMD: Avoid -Wformat warning with clang-15
  2024-04-05 20:49 [PATCH] x86: microcode: avoid -Wformat warning with clang-15 Arnd Bergmann
@ 2024-04-05 21:51 ` tip-bot2 for Arnd Bergmann
  2024-04-05 21:55 ` [PATCH] x86: microcode: avoid " Justin Stitt
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Arnd Bergmann @ 2024-04-05 21:51 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Arnd Bergmann, Borislav Petkov (AMD), x86, linux-kernel

The following commit has been merged into the x86/microcode branch of tip:

Commit-ID:     9e11fc78e2df7a2649764413029441a0c897fb11
Gitweb:        https://git.kernel.org/tip/9e11fc78e2df7a2649764413029441a0c897fb11
Author:        Arnd Bergmann <arnd@arndb.de>
AuthorDate:    Fri, 05 Apr 2024 22:49:07 +02:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Fri, 05 Apr 2024 23:26:18 +02:00

x86/microcode/AMD: Avoid -Wformat warning with clang-15

Older versions of clang show a warning for amd.c after a fix for a gcc
warning:

  arch/x86/kernel/cpu/microcode/amd.c:478:47: error: format specifies type \
    'unsigned char' but the argument has type 'u16' (aka 'unsigned short') [-Werror,-Wformat]
                           "amd-ucode/microcode_amd_fam%02hhxh.bin", family);
                                                       ~~~~~~        ^~~~~~
                                                       %02hx

In clang-16 and higher, this warning is disabled by default, but clang-15 is
still supported, and it's trivial to avoid by adapting the types according
to the range of the passed data and the format string.

  [ bp: Massage commit message. ]

Fixes: 2e9064faccd1 ("x86/microcode/amd: Fix snprintf() format string warning in W=1 build")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20240405204919.1003409-1-arnd@kernel.org
---
 arch/x86/kernel/cpu/microcode/amd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
index 13b45b9..620f0af 100644
--- a/arch/x86/kernel/cpu/microcode/amd.c
+++ b/arch/x86/kernel/cpu/microcode/amd.c
@@ -465,7 +465,7 @@ static bool early_apply_microcode(u32 cpuid_1_eax, u32 old_rev, void *ucode, siz
 	return !__apply_microcode_amd(mc);
 }
 
-static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)
+static bool get_builtin_microcode(struct cpio_data *cp, u8 family)
 {
 	char fw_name[36] = "amd-ucode/microcode_amd.bin";
 	struct firmware fw;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86: microcode: avoid -Wformat warning with clang-15
  2024-04-05 20:49 [PATCH] x86: microcode: avoid -Wformat warning with clang-15 Arnd Bergmann
  2024-04-05 21:51 ` [tip: x86/microcode] x86/microcode/AMD: Avoid " tip-bot2 for Arnd Bergmann
@ 2024-04-05 21:55 ` Justin Stitt
  1 sibling, 0 replies; 3+ messages in thread
From: Justin Stitt @ 2024-04-05 21:55 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Borislav Petkov, Arnd Bergmann, Thomas Gleixner, Ingo Molnar,
	Dave Hansen, x86, H. Peter Anvin, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Ashok Raj, Nathan Fontenot,
	Paolo Bonzini, linux-kernel, llvm

On Fri, Apr 5, 2024 at 1:49 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> Older versions of clang show a warning for amd.c after a fix for a gcc
> warning:
>
> arch/x86/kernel/cpu/microcode/amd.c:478:47: error: format specifies type 'unsigned char' but the argument has type 'u16' (aka 'unsigned short') [-Werror,-Wformat]
>                          "amd-ucode/microcode_amd_fam%02hhxh.bin", family);
>                                                      ~~~~~~        ^~~~~~
>                                                      %02hx
>
> In clang-16 and higher, this warning is disabled by default, but clang-15 is
> still supported, and it's trivial to avoid by adapting the types according
> to the range of the passed data and the format string.
>
> Fixes: 2e9064faccd1 ("x86/microcode/amd: Fix snprintf() format string warning in W=1 build")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Yeah the family only needs a byte so this is OK.

Reviewed-by: Justin Stitt <justinstitt@google.com>

> ---
>  arch/x86/kernel/cpu/microcode/amd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
> index 13b45b9c806d..620f0af713ca 100644
> --- a/arch/x86/kernel/cpu/microcode/amd.c
> +++ b/arch/x86/kernel/cpu/microcode/amd.c
> @@ -465,7 +465,7 @@ static bool early_apply_microcode(u32 cpuid_1_eax, u32 old_rev, void *ucode, siz
>         return !__apply_microcode_amd(mc);
>  }
>
> -static bool get_builtin_microcode(struct cpio_data *cp, unsigned int family)
> +static bool get_builtin_microcode(struct cpio_data *cp, u8 family)
>  {
>         char fw_name[36] = "amd-ucode/microcode_amd.bin";
>         struct firmware fw;
> --
> 2.39.2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-05 21:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-05 20:49 [PATCH] x86: microcode: avoid -Wformat warning with clang-15 Arnd Bergmann
2024-04-05 21:51 ` [tip: x86/microcode] x86/microcode/AMD: Avoid " tip-bot2 for Arnd Bergmann
2024-04-05 21:55 ` [PATCH] x86: microcode: avoid " Justin Stitt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox