]> git.baikalelectronics.ru Git - kernel.git/commit
net: amd-xgbe: fix clang -Wformat warning
authorJustin Stitt <jstitt007@gmail.com>
Tue, 7 Jun 2022 19:11:19 +0000 (12:11 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 9 Jun 2022 04:12:03 +0000 (21:12 -0700)
commit647df0d41b6bd8f4987dde6e8d8d0aba5b082985
tree4fbc8d9ea552e07415b4579e767026d14c8d85fd
parente67b72b90b7e19a4be4d9c29f3feea6f58ab43f8
net: amd-xgbe: fix clang -Wformat warning

see warning:
| drivers/net/ethernet/amd/xgbe/xgbe-drv.c:2787:43: warning: format specifies
| type 'unsigned short' but the argument has type 'int' [-Wformat]
|        netdev_dbg(netdev, "Protocol: %#06hx\n", ntohs(eth->h_proto));
|                                      ~~~~~~     ^~~~~~~~~~~~~~~~~~~

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

Also, 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.`

Since the argument is a u16 it will get promoted to an int and thus it is
most accurate to use the %x format specifier here. It should be noted that the
`#06` formatting sugar does not alter the promotion rules.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Signed-off-by: Justin Stitt <jstitt007@gmail.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Link: https://lore.kernel.org/r/20220607191119.20686-1-jstitt007@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/amd/xgbe/xgbe-drv.c