]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: spacemit: Fix error handling in emac_tx_mem_map()
authorVivian Wang <wangruikang@iscas.ac.cn>
Thu, 5 Mar 2026 06:39:39 +0000 (14:39 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 7 Mar 2026 02:58:34 +0000 (18:58 -0800)
The DMA mappings were leaked on mapping error. Free them with the
existing emac_free_tx_buf() function.

Fixes: bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC")
Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Link: https://patch.msgid.link/20260305-k1-ethernet-more-fixes-v2-2-e4e434d65055@iscas.ac.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/spacemit/k1_emac.c

index 5a5cb61be08ca8e748f9cbe240f21f07d3d52530..15d43e4a748bb9c51ff0852cb0abcea078ab3ea0 100644 (file)
@@ -733,7 +733,7 @@ static void emac_tx_mem_map(struct emac_priv *priv, struct sk_buff *skb)
        struct emac_desc tx_desc, *tx_desc_addr;
        struct device *dev = &priv->pdev->dev;
        struct emac_tx_desc_buffer *tx_buf;
-       u32 head, old_head, frag_num, f;
+       u32 head, old_head, frag_num, f, i;
        bool buf_idx;
 
        frag_num = skb_shinfo(skb)->nr_frags;
@@ -801,6 +801,15 @@ static void emac_tx_mem_map(struct emac_priv *priv, struct sk_buff *skb)
 
 err_free_skb:
        dev_dstats_tx_dropped(priv->ndev);
+
+       i = old_head;
+       while (i != head) {
+               emac_free_tx_buf(priv, i);
+
+               if (++i == tx_ring->total_cnt)
+                       i = 0;
+       }
+
        dev_kfree_skb_any(skb);
 }