* [PATCH] net: amd-xgbe: fix clang -Wformat warning
@ 2022-06-07 19:11 Justin Stitt
2022-06-07 20:44 ` Nick Desaulniers
2022-06-09 4:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Justin Stitt @ 2022-06-07 19:11 UTC (permalink / raw)
To: Tom Lendacky
Cc: llvm, Nick Desaulniers, Nathan Chancellor, netdev, Justin Stitt
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>
---
drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
index a3593290886f..4d46780fad13 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
@@ -2784,7 +2784,7 @@ void xgbe_print_pkt(struct net_device *netdev, struct sk_buff *skb, bool tx_rx)
netdev_dbg(netdev, "Dst MAC addr: %pM\n", eth->h_dest);
netdev_dbg(netdev, "Src MAC addr: %pM\n", eth->h_source);
- netdev_dbg(netdev, "Protocol: %#06hx\n", ntohs(eth->h_proto));
+ netdev_dbg(netdev, "Protocol: %#06x\n", ntohs(eth->h_proto));
for (i = 0; i < skb->len; i += 32) {
unsigned int len = min(skb->len - i, 32U);
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: amd-xgbe: fix clang -Wformat warning
2022-06-07 19:11 [PATCH] net: amd-xgbe: fix clang -Wformat warning Justin Stitt
@ 2022-06-07 20:44 ` Nick Desaulniers
2022-06-09 4:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Nick Desaulniers @ 2022-06-07 20:44 UTC (permalink / raw)
To: Justin Stitt
Cc: Tom Lendacky, llvm, Nathan Chancellor, netdev, David S. Miller,
Eric Dumazet, Jakub Kicinski, pabeni, Tom Rix, LKML
On Tue, Jun 7, 2022 at 12:11 PM Justin Stitt <jstitt007@gmail.com> wrote:
>
> 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>
LGTM; thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Don't forget to cc everyone from ./scripts/get_maintainer.pl!
$ /scripts/get_maintainer.pl
20220607_jstitt007_net_amd_xgbe_fix_clang_wformat_warning.mbx
Tom Lendacky <thomas.lendacky@amd.com> (supporter:AMD XGBE DRIVER)
"David S. Miller" <davem@davemloft.net> (maintainer:NETWORKING DRIVERS)
Eric Dumazet <edumazet@google.com> (maintainer:NETWORKING DRIVERS)
Jakub Kicinski <kuba@kernel.org> (maintainer:NETWORKING DRIVERS)
Paolo Abeni <pabeni@redhat.com> (maintainer:NETWORKING DRIVERS)
Nathan Chancellor <nathan@kernel.org> (supporter:CLANG/LLVM BUILD SUPPORT)
Nick Desaulniers <ndesaulniers@google.com> (supporter:CLANG/LLVM BUILD SUPPORT)
Tom Rix <trix@redhat.com> (reviewer:CLANG/LLVM BUILD SUPPORT)
netdev@vger.kernel.org (open list:AMD XGBE DRIVER)
linux-kernel@vger.kernel.org (open list)
llvm@lists.linux.dev (open list:CLANG/LLVM BUILD SUPPORT)
> ---
> drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
> index a3593290886f..4d46780fad13 100644
> --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
> +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
> @@ -2784,7 +2784,7 @@ void xgbe_print_pkt(struct net_device *netdev, struct sk_buff *skb, bool tx_rx)
>
> netdev_dbg(netdev, "Dst MAC addr: %pM\n", eth->h_dest);
> netdev_dbg(netdev, "Src MAC addr: %pM\n", eth->h_source);
> - netdev_dbg(netdev, "Protocol: %#06hx\n", ntohs(eth->h_proto));
> + netdev_dbg(netdev, "Protocol: %#06x\n", ntohs(eth->h_proto));
>
> for (i = 0; i < skb->len; i += 32) {
> unsigned int len = min(skb->len - i, 32U);
> --
> 2.30.2
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: amd-xgbe: fix clang -Wformat warning
2022-06-07 19:11 [PATCH] net: amd-xgbe: fix clang -Wformat warning Justin Stitt
2022-06-07 20:44 ` Nick Desaulniers
@ 2022-06-09 4:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-06-09 4:20 UTC (permalink / raw)
To: Justin Stitt; +Cc: thomas.lendacky, llvm, ndesaulniers, nathan, netdev
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 7 Jun 2022 12:11:19 -0700 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- net: amd-xgbe: fix clang -Wformat warning
https://git.kernel.org/netdev/net/c/647df0d41b6b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-09 4:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-07 19:11 [PATCH] net: amd-xgbe: fix clang -Wformat warning Justin Stitt
2022-06-07 20:44 ` Nick Desaulniers
2022-06-09 4:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).