[PATCH net v2] net: stmmac: ethtool: validate TX coalesce before reprogramming RX
From: Linkui Xiao
Date: Sat Sep 19 2026 - 21:58:31 EST
From: Linkui Xiao <xiaolinkui@xxxxxxxxxx>
__stmmac_set_coalesce() applies the RX part of the request first and
only afterwards checks the TX parameters. The RX path already calls
stmmac_rx_watchdog() and stores rx_riwt[] and rx_coal_frames[], so when
the TX check rejects the request the driver returns -EINVAL after having
silently changed the hardware. A following ethtool -c then reports the
new RX values even though the command failed.
This became easy to hit once the per-queue interface was added.
__stmmac_get_coalesce() reports tx-usecs and tx-frames as 0 for a queue
index that is RX-only, and ethtool applies per-queue coalesce by reading
the current values first and sending them straight back. The next set is
therefore guaranteed to trip the test for both TX fields being zero,
right after the RX watchdog has been reprogrammed.
Move both TX checks in front of the RX block so a request is either
applied completely or rejected without touching the device.
Fixes: db2f2842e6f5 ("net: stmmac: add per-queue TX & RX coalesce ethtool support")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Linkui Xiao <xiaolinkui@xxxxxxxxxx>
---
v2:
- Trim the comment in front of the TX checks to one line; the reasoning
belongs in the changelog. (Andrew Lunn)
.../ethernet/stmicro/stmmac/stmmac_ethtool.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index 154cc0c7623d..e06d05c3b4c7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -850,6 +850,16 @@ static int __stmmac_set_coalesce(struct net_device *dev,
else if (queue >= max_cnt)
return -EINVAL;
+ /* Check TX parameters before applying any RX setting */
+
+ if (ec->tx_coalesce_usecs == 0 &&
+ ec->tx_max_coalesced_frames == 0)
+ return -EINVAL;
+
+ if (ec->tx_coalesce_usecs > STMMAC_MAX_COAL_TX_TICK ||
+ ec->tx_max_coalesced_frames > STMMAC_TX_MAX_FRAMES)
+ return -EINVAL;
+
if (priv->use_riwt) {
rx_riwt = stmmac_usec2riwt(ec->rx_coalesce_usecs, priv);
@@ -875,14 +885,6 @@ static int __stmmac_set_coalesce(struct net_device *dev,
}
}
- if ((ec->tx_coalesce_usecs == 0) &&
- (ec->tx_max_coalesced_frames == 0))
- return -EINVAL;
-
- if ((ec->tx_coalesce_usecs > STMMAC_MAX_COAL_TX_TICK) ||
- (ec->tx_max_coalesced_frames > STMMAC_TX_MAX_FRAMES))
- return -EINVAL;
-
if (all_queues) {
int i;
--
2.25.1