Skip to content

Commit a4fc088

Browse files
Yinjun Zhangkuba-moo
authored andcommitted
ethtool: fix the check logic of at least one channel for RX/TX
The command "ethtool -L <intf> combined 0" may clean the RX/TX channel count and skip the error path, since the attrs tb[ETHTOOL_A_CHANNELS_RX_COUNT] and tb[ETHTOOL_A_CHANNELS_TX_COUNT] are NULL in this case when recent ethtool is used. Tested using ethtool v5.10. Fixes: 7be9251 ("ethtool: check if there is at least one channel for TX/RX in the core") Signed-off-by: Yinjun Zhang <yinjun.zhang@corigine.com> Signed-off-by: Simon Horman <simon.horman@netronome.com> Signed-off-by: Louis Peens <louis.peens@netronome.com> Link: https://lore.kernel.org/r/20210225125102.23989-1-simon.horman@netronome.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent eee7ede commit a4fc088

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

‎net/ethtool/channels.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info)
116116
struct ethtool_channels channels = {};
117117
struct ethnl_req_info req_info = {};
118118
struct nlattr **tb = info->attrs;
119-
const struct nlattr *err_attr;
119+
u32 err_attr, max_rx_in_use = 0;
120120
const struct ethtool_ops *ops;
121121
struct net_device *dev;
122-
u32 max_rx_in_use = 0;
123122
int ret;
124123

125124
ret = ethnl_parse_header_dev_get(&req_info,
@@ -157,34 +156,35 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info)
157156

158157
/* ensure new channel counts are within limits */
159158
if (channels.rx_count > channels.max_rx)
160-
err_attr = tb[ETHTOOL_A_CHANNELS_RX_COUNT];
159+
err_attr = ETHTOOL_A_CHANNELS_RX_COUNT;
161160
else if (channels.tx_count > channels.max_tx)
162-
err_attr = tb[ETHTOOL_A_CHANNELS_TX_COUNT];
161+
err_attr = ETHTOOL_A_CHANNELS_TX_COUNT;
163162
else if (channels.other_count > channels.max_other)
164-
err_attr = tb[ETHTOOL_A_CHANNELS_OTHER_COUNT];
163+
err_attr = ETHTOOL_A_CHANNELS_OTHER_COUNT;
165164
else if (channels.combined_count > channels.max_combined)
166-
err_attr = tb[ETHTOOL_A_CHANNELS_COMBINED_COUNT];
165+
err_attr = ETHTOOL_A_CHANNELS_COMBINED_COUNT;
167166
else
168-
err_attr = NULL;
167+
err_attr = 0;
169168
if (err_attr) {
170169
ret = -EINVAL;
171-
NL_SET_ERR_MSG_ATTR(info->extack, err_attr,
170+
NL_SET_ERR_MSG_ATTR(info->extack, tb[err_attr],
172171
"requested channel count exceeds maximum");
173172
goto out_ops;
174173
}
175174

176175
/* ensure there is at least one RX and one TX channel */
177176
if (!channels.combined_count && !channels.rx_count)
178-
err_attr = tb[ETHTOOL_A_CHANNELS_RX_COUNT];
177+
err_attr = ETHTOOL_A_CHANNELS_RX_COUNT;
179178
else if (!channels.combined_count && !channels.tx_count)
180-
err_attr = tb[ETHTOOL_A_CHANNELS_TX_COUNT];
179+
err_attr = ETHTOOL_A_CHANNELS_TX_COUNT;
181180
else
182-
err_attr = NULL;
181+
err_attr = 0;
183182
if (err_attr) {
184183
if (mod_combined)
185-
err_attr = tb[ETHTOOL_A_CHANNELS_COMBINED_COUNT];
184+
err_attr = ETHTOOL_A_CHANNELS_COMBINED_COUNT;
186185
ret = -EINVAL;
187-
NL_SET_ERR_MSG_ATTR(info->extack, err_attr, "requested channel counts would result in no RX or TX channel being configured");
186+
NL_SET_ERR_MSG_ATTR(info->extack, tb[err_attr],
187+
"requested channel counts would result in no RX or TX channel being configured");
188188
goto out_ops;
189189
}
190190

0 commit comments

Comments
 (0)