Skip to content

Commit 628773a

Browse files
kuba-moogregkh
authored andcommitted
ethtool: fix ethtool msg len calculation for pause stats
[ Upstream commit 1aabe57 ] 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: 9a27a33 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e78c267 commit 628773a

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎include/linux/ethtool_netlink.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#define __ETHTOOL_LINK_MODE_MASK_NWORDS \
1111
DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32)
1212

13+
#define ETHTOOL_PAUSE_STAT_CNT (__ETHTOOL_A_PAUSE_STAT_CNT - \
14+
ETHTOOL_A_PAUSE_STAT_TX_FRAMES)
15+
1316
enum ethtool_multicast_groups {
1417
ETHNL_MCGRP_MONITOR,
1518
};

‎include/uapi/linux/ethtool_netlink.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ enum {
394394
ETHTOOL_A_PAUSE_STAT_TX_FRAMES,
395395
ETHTOOL_A_PAUSE_STAT_RX_FRAMES,
396396

397-
/* add new constants above here */
397+
/* add new constants above here
398+
* adjust ETHTOOL_PAUSE_STAT_CNT if adding non-stats!
399+
*/
398400
__ETHTOOL_A_PAUSE_STAT_CNT,
399401
ETHTOOL_A_PAUSE_STAT_MAX = (__ETHTOOL_A_PAUSE_STAT_CNT - 1)
400402
};

‎net/ethtool/pause.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ static int pause_reply_size(const struct ethnl_req_info *req_base,
6262

6363
if (req_base->flags & ETHTOOL_FLAG_STATS)
6464
n += nla_total_size(0) + /* _PAUSE_STATS */
65-
nla_total_size_64bit(sizeof(u64)) *
66-
(ETHTOOL_A_PAUSE_STAT_MAX - 2);
65+
nla_total_size_64bit(sizeof(u64)) * ETHTOOL_PAUSE_STAT_CNT;
6766
return n;
6867
}
6968

0 commit comments

Comments
 (0)