Skip to content

Commit bde292c

Browse files
Jie Wangkuba-moo
authored andcommitted
net: ethtool: move checks before rtnl_lock() in ethnl_set_rings
Currently these two checks in ethnl_set_rings are added after rtnl_lock() which will do useless works if the request is invalid. So this patch moves these checks before the rtnl_lock() to avoid these costs. Signed-off-by: Jie Wang <[email protected]> Signed-off-by: Guangbin Huang <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4dc84c0 commit bde292c

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

net/ethtool/rings.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info)
152152
if (!ops->get_ringparam || !ops->set_ringparam)
153153
goto out_dev;
154154

155+
if (tb[ETHTOOL_A_RINGS_RX_BUF_LEN] &&
156+
!(ops->supported_ring_params & ETHTOOL_RING_USE_RX_BUF_LEN)) {
157+
ret = -EOPNOTSUPP;
158+
NL_SET_ERR_MSG_ATTR(info->extack,
159+
tb[ETHTOOL_A_RINGS_RX_BUF_LEN],
160+
"setting rx buf len not supported");
161+
goto out_dev;
162+
}
163+
164+
if (tb[ETHTOOL_A_RINGS_CQE_SIZE] &&
165+
!(ops->supported_ring_params & ETHTOOL_RING_USE_CQE_SIZE)) {
166+
ret = -EOPNOTSUPP;
167+
NL_SET_ERR_MSG_ATTR(info->extack,
168+
tb[ETHTOOL_A_RINGS_CQE_SIZE],
169+
"setting cqe size not supported");
170+
goto out_dev;
171+
}
172+
155173
if (tb[ETHTOOL_A_RINGS_TX_PUSH] &&
156174
!(ops->supported_ring_params & ETHTOOL_RING_USE_TX_PUSH)) {
157175
ret = -EOPNOTSUPP;
@@ -201,24 +219,6 @@ int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info)
201219
goto out_ops;
202220
}
203221

204-
if (kernel_ringparam.rx_buf_len != 0 &&
205-
!(ops->supported_ring_params & ETHTOOL_RING_USE_RX_BUF_LEN)) {
206-
ret = -EOPNOTSUPP;
207-
NL_SET_ERR_MSG_ATTR(info->extack,
208-
tb[ETHTOOL_A_RINGS_RX_BUF_LEN],
209-
"setting rx buf len not supported");
210-
goto out_ops;
211-
}
212-
213-
if (kernel_ringparam.cqe_size &&
214-
!(ops->supported_ring_params & ETHTOOL_RING_USE_CQE_SIZE)) {
215-
ret = -EOPNOTSUPP;
216-
NL_SET_ERR_MSG_ATTR(info->extack,
217-
tb[ETHTOOL_A_RINGS_CQE_SIZE],
218-
"setting cqe size not supported");
219-
goto out_ops;
220-
}
221-
222222
ret = dev->ethtool_ops->set_ringparam(dev, &ringparam,
223223
&kernel_ringparam, info->extack);
224224
if (ret < 0)

0 commit comments

Comments
 (0)