Commit 80dcfb7e authored by Wei Fang's avatar Wei Fang Committed by Wentao Guan
Browse files

net: enetc: fix the off-by-one issue in enetc_map_tx_tso_buffs()

stable inclusion
from stable-v6.6.81
commit 12733d6e442aaa0004b9cdfda2f2a359ec9f08a1
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBYZED

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=12733d6e442aaa0004b9cdfda2f2a359ec9f08a1



--------------------------------

commit 249df695c3ffe8c8d36d46c2580ce72410976f96 upstream.

There is an off-by-one issue for the err_chained_bd path, it will free
one more tx_swbd than expected. But there is no such issue for the
err_map_data path. To fix this off-by-one issue and make the two error
handling consistent, the increment of 'i' and 'count' remain in sync
and enetc_unwind_tx_frame() is called for error handling.

Fixes: fb8629e2 ("net: enetc: add support for software TSO")
Cc: stable@vger.kernel.org
Suggested-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarWei Fang <wei.fang@nxp.com>
Reviewed-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarClaudiu Manoil <claudiu.manoil@nxp.com>
Link: https://patch.msgid.link/20250224111251.1061098-9-wei.fang@nxp.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 12733d6e442aaa0004b9cdfda2f2a359ec9f08a1)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent 4a635bd5
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -590,8 +590,13 @@ static int enetc_map_tx_tso_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb
			err = enetc_map_tx_tso_data(tx_ring, skb, tx_swbd, txbd,
						    tso.data, size,
						    size == data_len);
			if (err)
			if (err) {
				if (i == 0)
					i = tx_ring->bd_count;
				i--;

				goto err_map_data;
			}

			data_len -= size;
			count++;
@@ -620,13 +625,7 @@ static int enetc_map_tx_tso_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb
	dev_err(tx_ring->dev, "DMA map error");

err_chained_bd:
	do {
		tx_swbd = &tx_ring->tx_swbd[i];
		enetc_free_tx_frame(tx_ring, tx_swbd);
		if (i == 0)
			i = tx_ring->bd_count;
		i--;
	} while (count--);
	enetc_unwind_tx_frame(tx_ring, count, i);

	return 0;
}