Skip to contentSkip to conversation

IB/hifi1: add a null check of kzalloc_node in hfi1_ipoib_txreq_init

PATCH Applied void0red 2 participants 3 messages Feb 27, 2023 – Mar 13, 2023

Subsystems (2)
lore
Share & tools
lore

void0red

author
#0 lore raw

PATCH 1/1 IB/hifi1: add a null check of kzalloc_node in hfi1_ipoib_txreq_init

From: Kang Chen <[email protected]>

kzalloc_node may fails, check it and do the cleanup.

---
 drivers/infiniband/hw/hfi1/ipoib_tx.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/infiniband/hw/hfi1/ipoib_tx.c +4 -1
index 5d9a7b09c..349eb4139 100644
@@ -737,10 +737,13 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv)
 		txq->tx_ring.shift = ilog2(tx_item_size);
 		txq->tx_ring.avail = hfi1_ipoib_ring_hwat(txq);
 		tx_ring = &txq->tx_ring;
-		for (j = 0; j < tx_ring_size; j++)
+		for (j = 0; j < tx_ring_size; j++) {
 			hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr =
 				kzalloc_node(sizeof(*tx->sdma_hdr),
 					     GFP_KERNEL, priv->dd->node);
+			if (!hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr)
+				goto free_txqs;
+		}
 
 		netif_napi_add_tx(dev, &txq->napi, hfi1_ipoib_poll_tx_ring);
 	}
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · On Mon, Feb 27, 2023 at 06:02:12PM +0800, void0red wrote:

From: Kang Chen <[email protected]>

kzalloc_node may fails, check it and do the cleanup.

---
 drivers/infiniband/hw/hfi1/ipoib_tx.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Added Fixes line and applied.

Fixes b1151b74ff68 ("IB/hfi1: Fix alloc failure with larger txqueuelen")

Thanks

Quoted 23 lines
drivers/infiniband/hw/hfi1/ipoib_tx.c +4 -1
index 5d9a7b09c..349eb4139 100644
@@ -737,10 +737,13 @@ int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv)
 		txq->tx_ring.shift = ilog2(tx_item_size);
 		txq->tx_ring.avail = hfi1_ipoib_ring_hwat(txq);
 		tx_ring = &txq->tx_ring;
-		for (j = 0; j < tx_ring_size; j++)
+		for (j = 0; j < tx_ring_size; j++) {
 			hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr =
 				kzalloc_node(sizeof(*tx->sdma_hdr),
 					     GFP_KERNEL, priv->dd->node);
+			if (!hfi1_txreq_from_idx(tx_ring, j)->sdma_hdr)
+				goto free_txqs;
+		}
 
 		netif_napi_add_tx(dev, &txq->napi, hfi1_ipoib_poll_tx_ring);
 	}
Signature · 1 line
2.34.1