Message ID | 20220707182052.769989-1-justinstitt@google.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 5b47d2364652979dc43df14f7af19346a001b770 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [v2] net: rxrpc: fix clang -Wformat warning | expand |
On Thu, Jul 07, 2022 at 11:20:52AM -0700, Justin Stitt wrote: > When building with Clang we encounter this warning: > | net/rxrpc/rxkad.c:434:33: error: format specifies type 'unsigned short' > | but the argument has type 'u32' (aka 'unsigned int') [-Werror,-Wformat] > | _leave(" = %d [set %hx]", ret, y); > > y is a u32 but the format specifier is `%hx`. Going from unsigned int to > short int results in a loss of data. This is surely not intended > behavior. If it is intended, the warning should be suppressed through > other means. > > This patch should get us closer to the goal of enabling the -Wformat > flag for Clang builds. > > Link: https://github.com/ClangBuiltLinux/linux/issues/378 > Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Nathan Chancellor <nathan@kernel.org> > --- > diff from v1 -> v2: > * Change format specifier from %u to %x to properly represent hexadecimal. > > net/rxrpc/rxkad.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c > index 08aab5c01437..258917a714c8 100644 > --- a/net/rxrpc/rxkad.c > +++ b/net/rxrpc/rxkad.c > @@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call, > break; > } > > - _leave(" = %d [set %hx]", ret, y); > + _leave(" = %d [set %x]", ret, y); > return ret; > } > > -- > 2.37.0.rc0.161.g10f37bed90-goog >
Justin Stitt <justinstitt@google.com> wrote: > y is a u32 but the format specifier is `%hx`. Going from unsigned int to > short int results in a loss of data. This is surely not intended > behavior. If it is intended, the warning should be suppressed through > other means. Yeah, y is reduced to a 16-bit number so that it can be used in the protocol, but the type is still 32-bit because that's needed for the calculation. An alternative would be to print sp->hdr.cksum since that's the value that will appear on the wire, but I've no objection to this change either. > This patch should get us closer to the goal of enabling the -Wformat > flag for Clang builds. > > Link: https://github.com/ClangBuiltLinux/linux/issues/378 > Signed-off-by: Justin Stitt <justinstitt@google.com> Acked-by: David Howells <dhowells@redhat.com>
Hello: This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <kuba@kernel.org>: On Thu, 7 Jul 2022 11:20:52 -0700 you wrote: > When building with Clang we encounter this warning: > | net/rxrpc/rxkad.c:434:33: error: format specifies type 'unsigned short' > | but the argument has type 'u32' (aka 'unsigned int') [-Werror,-Wformat] > | _leave(" = %d [set %hx]", ret, y); > > y is a u32 but the format specifier is `%hx`. Going from unsigned int to > short int results in a loss of data. This is surely not intended > behavior. If it is intended, the warning should be suppressed through > other means. > > [...] Here is the summary with links: - [v2] net: rxrpc: fix clang -Wformat warning https://git.kernel.org/netdev/net-next/c/5b47d2364652 You are awesome, thank you!
diff from v1 -> v2: * Change format specifier from %u to %x to properly represent hexadecimal. net/rxrpc/rxkad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c index 08aab5c01437..258917a714c8 100644 --- a/net/rxrpc/rxkad.c +++ b/net/rxrpc/rxkad.c @@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call, break; } - _leave(" = %d [set %hx]", ret, y); + _leave(" = %d [set %x]", ret, y); return ret; }
When building with Clang we encounter this warning: | net/rxrpc/rxkad.c:434:33: error: format specifies type 'unsigned short' | but the argument has type 'u32' (aka 'unsigned int') [-Werror,-Wformat] | _leave(" = %d [set %hx]", ret, y); y is a u32 but the format specifier is `%hx`. Going from unsigned int to short int results in a loss of data. This is surely not intended behavior. If it is intended, the warning should be suppressed through other means. This patch should get us closer to the goal of enabling the -Wformat flag for Clang builds. Link: https://github.com/ClangBuiltLinux/linux/issues/378 Signed-off-by: Justin Stitt <justinstitt@google.com> ---