[PATCH net] net: mellanox: mlxbf_gige: Fix skb_panic splat under memory pressure
From: Thomas Bogendoerfer
Date: Mon May 22 2023 - 15:07:27 EST
Do skp_put() after a new skb has been successfully allocated otherwise
the reused skb leads to skp_panics or incorrect packet sizes.
Signed-off-by: Thomas Bogendoerfer <tbogendoerfer@xxxxxxx>
---
.../ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c
index afa3b92a6905..2c132849a76d 100644
--- a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c
+++ b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_rx.c
@@ -245,18 +245,19 @@ static bool mlxbf_gige_rx_packet(struct mlxbf_gige *priv, int *rx_pkts)
skb = priv->rx_skb[rx_pi_rem];
- skb_put(skb, datalen);
-
- skb->ip_summed = CHECKSUM_NONE; /* device did not checksum packet */
-
- skb->protocol = eth_type_trans(skb, netdev);
-
/* Alloc another RX SKB for this same index */
rx_skb = mlxbf_gige_alloc_skb(priv, MLXBF_GIGE_DEFAULT_BUF_SZ,
&rx_buf_dma, DMA_FROM_DEVICE);
if (!rx_skb)
return false;
priv->rx_skb[rx_pi_rem] = rx_skb;
+
+ skb_put(skb, datalen);
+
+ skb->ip_summed = CHECKSUM_NONE; /* device did not checksum packet */
+
+ skb->protocol = eth_type_trans(skb, netdev);
+
dma_unmap_single(priv->dev, *rx_wqe_addr,
MLXBF_GIGE_DEFAULT_BUF_SZ, DMA_FROM_DEVICE);
*rx_wqe_addr = rx_buf_dma;
--
2.35.3