net: amd-xgbe: fix clang -Wformat warning
Subsystems (3)
PATCH 1/1 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.
--- drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/amd/xgbe/xgbe-drv.c +1 -1
@@ -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 );
Signature · 1 line
2.30.2
Quoted 17 lines · 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.rstspecifically 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.
Quoted 6 lines
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
#06formatting sugar does not alter the promotion rules.
LGTM; thanks for the patch!
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 <[email protected]> (supporter:AMD XGBE DRIVER) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS) Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS) Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS) Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS) Nathan Chancellor <[email protected]> (supporter:CLANG/LLVM BUILD SUPPORT) Nick Desaulniers <[email protected]> (supporter:CLANG/LLVM BUILD SUPPORT) Tom Rix <[email protected]> (reviewer:CLANG/LLVM BUILD SUPPORT) [email protected] (open list:AMD XGBE DRIVER) [email protected] (open list) [email protected] (open list:CLANG/LLVM BUILD SUPPORT)
Quoted 20 lines
--- drivers/net/ethernet/amd/xgbe/xgbe-drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ethernet/amd/xgbe/xgbe-drv.c +1
-2@@ -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
Signature · 2 lines
Thanks, ~Nick Desaulniers
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · 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.rstspecifically 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html