ethtool: fix ethtool msg len calculation for pause stats
authorJakub Kicinski <kuba@kernel.org>
Tue, 2 Nov 2021 22:02:36 +0000 (15:02 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 3 Nov 2021 11:20:45 +0000 (11:20 +0000)
ETHTOOL_A_PAUSE_STAT_MAX is the MAX attribute id,
so we need to subtract non-stats and add one to
get a count (IOW -2+1 == -1).

Otherwise we'll see:

  ethnl cmd 21: calculated reply length 40, but consumed 52

Fixes: 9a27a33027f2 ("ethtool: add standard pause stats")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/ethtool_netlink.h
include/uapi/linux/ethtool_netlink.h
net/ethtool/pause.c

index 1e7bf78cb3829cc4059862a1256746d562492116..aba348d58ff61c5265b76c3e51f83417582e519e 100644 (file)
@@ -10,6 +10,9 @@
 #define __ETHTOOL_LINK_MODE_MASK_NWORDS \
        DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32)
 
+#define ETHTOOL_PAUSE_STAT_CNT (__ETHTOOL_A_PAUSE_STAT_CNT -           \
+                                ETHTOOL_A_PAUSE_STAT_TX_FRAMES)
+
 enum ethtool_multicast_groups {
        ETHNL_MCGRP_MONITOR,
 };
index ca5fbb59fa4212dc26e420d93d9e4136f2c1d5ae..999777d32dcfdce5360353c445cfb965af808b6d 100644 (file)
@@ -411,7 +411,9 @@ enum {
        ETHTOOL_A_PAUSE_STAT_TX_FRAMES,
        ETHTOOL_A_PAUSE_STAT_RX_FRAMES,
 
-       /* add new constants above here */
+       /* add new constants above here
+        * adjust ETHTOOL_PAUSE_STAT_CNT if adding non-stats!
+        */
        __ETHTOOL_A_PAUSE_STAT_CNT,
        ETHTOOL_A_PAUSE_STAT_MAX = (__ETHTOOL_A_PAUSE_STAT_CNT - 1)
 };
index 9009f412151e7878bed59ae4dec9d0b91382241a..ee1e5806bc93a4bf60fe18bf15ee9b01af190b62 100644 (file)
@@ -56,8 +56,7 @@ static int pause_reply_size(const struct ethnl_req_info *req_base,
 
        if (req_base->flags & ETHTOOL_FLAG_STATS)
                n += nla_total_size(0) +        /* _PAUSE_STATS */
-                       nla_total_size_64bit(sizeof(u64)) *
-                               (ETHTOOL_A_PAUSE_STAT_MAX - 2);
+                    nla_total_size_64bit(sizeof(u64)) * ETHTOOL_PAUSE_STAT_CNT;
        return n;
 }