net: ipv4: fix clang -Wformat warnings
authorJustin Stitt <justinstitt@google.com>
Sat, 9 Jul 2022 00:37:04 +0000 (17:37 -0700)
committerSteffen Klassert <steffen.klassert@secunet.com>
Tue, 12 Jul 2022 10:58:53 +0000 (12:58 +0200)
commite79b9473e9b59e83e23db9b7411c6080b5a6826d
tree5fcc14b11be11307dd7e0c6ad3ddce20f8a5fb52
parentf85daf0e725358be78dfd208dea5fd665d8cb901
net: ipv4: fix clang -Wformat warnings

When building with Clang we encounter these warnings:
| net/ipv4/ah4.c:513:4: error: format specifies type 'unsigned short' but
| the argument has type 'int' [-Werror,-Wformat]
| aalg_desc->uinfo.auth.icv_fullbits / 8);
-
| net/ipv4/esp4.c:1114:5: error: format specifies type 'unsigned short'
| but the argument has type 'int' [-Werror,-Wformat]
| aalg_desc->uinfo.auth.icv_fullbits / 8);

`aalg_desc->uinfo.auth.icv_fullbits` is a u16 but due to default
argument promotion becomes an int.

Variadic functions (printf-like) undergo default argument promotion.
Documentation/core-api/printk-formats.rst specifically recommends using
the promoted-to-type's format flag.

As per C11 6.3.1.1:
(https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf) `If an int
can represent all values of the original type ..., the value is
converted to an int; otherwise, it is converted to an unsigned int.
These are called the integer promotions.` Thus it makes sense to change
%hu to %d not only to follow this standard but to suppress the warning
as well.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Signed-off-by: Justin Stitt <justinstitt@google.com>
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Nathan Chancellor <nathan@kernel.org>
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/ipv4/ah4.c
net/ipv4/esp4.c