]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: enetc: fix the off-by-one issue in enetc_map_tx_tso_buffs()
authorWei Fang <wei.fang@nxp.com>
Mon, 24 Feb 2025 11:12:51 +0000 (19:12 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Mar 2025 17:25:41 +0000 (18:25 +0100)
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: fb8629e2cbfc ("net: enetc: add support for software TSO")
Cc: stable@vger.kernel.org
Suggested-by: Vladimir Oltean <vladimir.oltean@nxp.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-9-wei.fang@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/ethernet/freescale/enetc/enetc.c

index 4d7e29d039665897762909e8c2aa7b1a5a4ff063..f662a5d54986cf6a1a70e3ad7c635649755d6620 100644 (file)
@@ -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 @@ err_map_data:
        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;
 }