ethtool: fix ethtool msg len calculation for pause stats
Subsystems (3)
Jakub Kicinski
maintainerPATCH v2 1/1 ethtool: fix ethtool msg len calculation for pause stats
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
---
v2: add a define
include/linux/ethtool_netlink.h | 3 +++ include/uapi/linux/ethtool_netlink.h | 4 +++- net/ethtool/pause.c | 3 +-- 3 files changed, 7 insertions(+), 3 deletions(-)
include/linux/ethtool_netlink.h +3 -0
@@ -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 , };
include/uapi/linux/ethtool_netlink.h +3 -1
@@ -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) };
net/ethtool/pause.c +1 -2
@@ -56,8 +56,7 @@ static int pause_reply_size(const struct ethnl_req_info *req_base,if (req_base->flags ÐTOOL_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; }
Signature · 1 line
2.31.1
Quoted 10 lines · Jakub Kicinski
ETHTOOL_A_PAUSE_STAT_MAXis 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 <[email protected]>
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:
Quoted 9 lines · On Tue, 2 Nov 2021 15:02:36 -0700 you wrote:
ETHTOOL_A_PAUSE_STAT_MAXis 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
[...]
Here is the summary with links:
- [net,v2] ethtool: fix ethtool msg len calculation for pause stats
https://git.kernel.org/netdev/net/c/1aabe578dd86
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html