Commit d2848c77 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_buffs()

stable inclusion
from stable-v6.6.81
commit 9561b0550c496aecc21f20261ea8d0d388fe69c4
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=9561b0550c496aecc21f20261ea8d0d388fe69c4



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

commit 39ab773e4c120f7f98d759415ccc2aca706bbc10 upstream.

When a DMA mapping error occurs while processing skb frags, it will free
one more tx_swbd than expected, so fix this off-by-one issue.

Fixes: d4fd0404 ("enetc: Introduce basic PF and VF ENETC ethernet drivers")
Cc: stable@vger.kernel.org
Suggested-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Suggested-by: default avatarMichal Swiatkowski <michal.swiatkowski@linux.intel.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-2-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 9561b0550c496aecc21f20261ea8d0d388fe69c4)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent ec9492bc
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -145,6 +145,24 @@ static int enetc_ptp_parse(struct sk_buff *skb, u8 *udp,
	return 0;
}

/**
 * enetc_unwind_tx_frame() - Unwind the DMA mappings of a multi-buffer Tx frame
 * @tx_ring: Pointer to the Tx ring on which the buffer descriptors are located
 * @count: Number of Tx buffer descriptors which need to be unmapped
 * @i: Index of the last successfully mapped Tx buffer descriptor
 */
static void enetc_unwind_tx_frame(struct enetc_bdr *tx_ring, int count, int i)
{
	while (count--) {
		struct enetc_tx_swbd *tx_swbd = &tx_ring->tx_swbd[i];

		enetc_free_tx_frame(tx_ring, tx_swbd);
		if (i == 0)
			i = tx_ring->bd_count;
		i--;
	}
}

static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
{
	bool do_vlan, do_onestep_tstamp = false, do_twostep_tstamp = false;
@@ -328,13 +346,7 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
dma_err:
	dev_err(tx_ring->dev, "DMA map error");

	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;
}