Skip to content

Commit 39ab773

Browse files
Wei Fangkuba-moo
authored andcommitted
net: enetc: fix the off-by-one issue in enetc_map_tx_buffs()
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: d4fd040 ("enetc: Introduce basic PF and VF ENETC ethernet drivers") Cc: [email protected] Suggested-by: Vladimir Oltean <[email protected]> Suggested-by: Michal Swiatkowski <[email protected]> Signed-off-by: Wei Fang <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Reviewed-by: Claudiu Manoil <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 85c7ca9 commit 39ab773

File tree

1 file changed

+19
-7
lines changed
  • drivers/net/ethernet/freescale/enetc

1 file changed

+19
-7
lines changed

drivers/net/ethernet/freescale/enetc/enetc.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ static bool enetc_skb_is_tcp(struct sk_buff *skb)
167167
return skb->csum_offset == offsetof(struct tcphdr, check);
168168
}
169169

170+
/**
171+
* enetc_unwind_tx_frame() - Unwind the DMA mappings of a multi-buffer Tx frame
172+
* @tx_ring: Pointer to the Tx ring on which the buffer descriptors are located
173+
* @count: Number of Tx buffer descriptors which need to be unmapped
174+
* @i: Index of the last successfully mapped Tx buffer descriptor
175+
*/
176+
static void enetc_unwind_tx_frame(struct enetc_bdr *tx_ring, int count, int i)
177+
{
178+
while (count--) {
179+
struct enetc_tx_swbd *tx_swbd = &tx_ring->tx_swbd[i];
180+
181+
enetc_free_tx_frame(tx_ring, tx_swbd);
182+
if (i == 0)
183+
i = tx_ring->bd_count;
184+
i--;
185+
}
186+
}
187+
170188
static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
171189
{
172190
bool do_vlan, do_onestep_tstamp = false, do_twostep_tstamp = false;
@@ -372,13 +390,7 @@ static int enetc_map_tx_buffs(struct enetc_bdr *tx_ring, struct sk_buff *skb)
372390
dma_err:
373391
dev_err(tx_ring->dev, "DMA map error");
374392

375-
do {
376-
tx_swbd = &tx_ring->tx_swbd[i];
377-
enetc_free_tx_frame(tx_ring, tx_swbd);
378-
if (i == 0)
379-
i = tx_ring->bd_count;
380-
i--;
381-
} while (count--);
393+
enetc_unwind_tx_frame(tx_ring, count, i);
382394

383395
return 0;
384396
}

0 commit comments

Comments
 (0)