]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: enetc: fix the off-by-one issue in enetc_map_tx_buffs()
authorWei Fang <wei.fang@nxp.com>
Mon, 24 Feb 2025 11:12:44 +0000 (19:12 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 26 Feb 2025 03:10:58 +0000 (19:10 -0800)
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: d4fd0404c1c9 ("enetc: Introduce basic PF and VF ENETC ethernet drivers")
Cc: stable@vger.kernel.org
Suggested-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Suggested-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Signed-off-by: Wei Fang <wei.fang@nxp.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Link: https://patch.msgid.link/20250224111251.1061098-2-wei.fang@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/freescale/enetc/enetc.c

index 6a6fc819dfdeeb13e8ba03f7ec9cba6c91a2afaf..55ad31a5073e7eb23188ad0cd5e00d527b29b6a4 100644 (file)
@@ -167,6 +167,24 @@ static bool enetc_skb_is_tcp(struct sk_buff *skb)
        return skb->csum_offset == offsetof(struct tcphdr, check);
 }
 
+/**
+ * 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;
@@ -372,13 +390,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;
 }