Skip to content

Commit 647df0d

Browse files
JustinStittkuba-moo
authored andcommitted
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 `#6` formatting sugar does not alter the promotion rules. Link: ClangBuiltLinux#378 Signed-off-by: Justin Stitt <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e67b72b commit 647df0d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/net/ethernet/amd/xgbe/xgbe-drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ void xgbe_print_pkt(struct net_device *netdev, struct sk_buff *skb, bool tx_rx)
27842784

27852785
netdev_dbg(netdev, "Dst MAC addr: %pM\n", eth->h_dest);
27862786
netdev_dbg(netdev, "Src MAC addr: %pM\n", eth->h_source);
2787-
netdev_dbg(netdev, "Protocol: %#06hx\n", ntohs(eth->h_proto));
2787+
netdev_dbg(netdev, "Protocol: %#06x\n", ntohs(eth->h_proto));
27882788

27892789
for (i = 0; i < skb->len; i += 32) {
27902790
unsigned int len = min(skb->len - i, 32U);

0 commit comments

Comments
 (0)