net: rxrpc: fix clang -Wformat warning
Subsystems (3)
PATCH 1/1 net: rxrpc: fix clang -Wformat warning
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.
--- net/rxrpc/rxkad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/rxkad.c +1 -1
@@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call,break ; } -_leave (" = %d [set %hx]" , ret, y); +_leave (" = %d [set %u]" , ret, y);return ret; }
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Hi Justin,
Quoted 24 lines · Justin Stitt
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.
Signed-off-by Justin Stitt <[email protected]>--- net/rxrpc/rxkad.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/rxrpc/rxkad.c +0
-0
net/rxrpc/rxkad.c static int rxkad_secure_packet(struct rxrpc_call *call, · line 434
Quoted 5 lines
net/rxrpc/rxkad.c +1
-1@@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call,break ; } -_leave (" = %d [set %hx]" , ret, y); +_leave (" = %d [set %u]" , ret, y);
Should this just become %x to keep printing it as a hexidecimal number?
Cheers,
Nathan
Quoted 6 lines
net/rxrpc/rxkad.c +0
-0return ret; }Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
PATCH v2 1/1 net: rxrpc: fix clang -Wformat warning
In reply to Justin StittWhen 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.
---
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(-)
net/rxrpc/rxkad.c +1 -1
@@ -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; }
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Quoted 10 lines · Justin Stitt
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.
Quoted 5 lines
This patch should get us closer to the goal of enabling the -Wformat flag for Clang builds.
Quoted 23 lines
---
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(-)net/rxrpc/rxkad.c +1
-1@@ -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; }Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Quoted 4 lines · Justin Stitt
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.
Quoted 5 lines
This patch should get us closer to the goal of enabling the -Wformat flag for Clang builds.
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 4 lines · Justin Stitt
When building with Clang we encounter this warning:
Quoted 3 lines
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);
Does anyone still use these debugging macros in rxrpc or is it historic cruft?
net/rxrpc/ar-internal.h-#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) net/rxrpc/ar-internal.h-#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
net/rxrpc/ar-internal.h-#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
net/rxrpc/ar-internal.h-#define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
net/rxrpc/ar-internal.h-#define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__)
etc...
[]
net/rxrpc/Kconfig:config AF_RXRPC_DEBUGnet/rxrpc/Kconfig- bool "RxRPC dynamic debugging"net/rxrpc/Kconfig- helpnet/rxrpc/Kconfig- Say Y here to make runtime controllable debugging messages appear.net/rxrpc/Kconfig-net/rxrpc/Kconfig- See Documentation/networking/rxrpc.rst
This seems to show there is debugging documentation, but it doesn't seem to exist in this file.
net/rxrpc/rxkad.c
Quoted 1 line
net/rxrpc/rxkad.c +0
-0
[]
Quoted 9 lines
net/rxrpc/rxkad.c +1
-1@@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call,break ; } -_leave (" = %d [set %hx]" , ret, y); +_leave (" = %d [set %u]" , ret, y);return ret; }
David Howells
maintainerQuoted 1 line · Joe Perches
Does anyone still use these debugging macros in rxrpc
Yes.
David
David Howells
maintainerQuoted 9 lines · Joe Perches
net/rxrpc/Kconfig:config
AF_RXRPC_DEBUGnet/rxrpc/Kconfig-bool "RxRPC dynamic debugging"net/rxrpc/Kconfig-helpnet/rxrpc/Kconfig-Say Y here to make runtime controllable debugging messages appear.net/rxrpc/Kconfig-net/rxrpc/Kconfig-SeeDocumentation/networking/rxrpc.rstThis seems to show there is debugging documentation, but it doesn't seem to exist in this file.
Try looking in net/rxrpc/ar-internal.h:
#elif defined(CONFIG_AF_RXRPC_DEBUG)
David