Skip to content

Commit f329924

Browse files
LorenzoBianconiPaolo Abeni
authored andcommitted
net: airoha: Move ndesc initialization at end of airoha_qdma_init_tx()
If queue entry list allocation fails in airoha_qdma_init_tx_queue routine, airoha_qdma_cleanup_tx_queue() will trigger a NULL pointer dereference accessing the queue entry array. The issue is due to the early ndesc initialization in airoha_qdma_init_tx_queue(). Fix the issue moving ndesc initialization at end of airoha_qdma_init_tx routine. Fixes: 3f47e67 ("net: airoha: Add the capability to consume out-of-order DMA tx descriptors") Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Link: https://patch.msgid.link/20260417-airoha_qdma_cleanup_tx_queue-fix-net-v4-1-e04bcc2c9642@kernel.org Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 1ada03f commit f329924

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/net/ethernet/airoha/airoha_eth.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -978,27 +978,27 @@ static int airoha_qdma_init_tx_queue(struct airoha_queue *q,
978978
dma_addr_t dma_addr;
979979

980980
spin_lock_init(&q->lock);
981-
q->ndesc = size;
982981
q->qdma = qdma;
983982
q->free_thr = 1 + MAX_SKB_FRAGS;
984983
INIT_LIST_HEAD(&q->tx_list);
985984

986-
q->entry = devm_kzalloc(eth->dev, q->ndesc * sizeof(*q->entry),
985+
q->entry = devm_kzalloc(eth->dev, size * sizeof(*q->entry),
987986
GFP_KERNEL);
988987
if (!q->entry)
989988
return -ENOMEM;
990989

991-
q->desc = dmam_alloc_coherent(eth->dev, q->ndesc * sizeof(*q->desc),
990+
q->desc = dmam_alloc_coherent(eth->dev, size * sizeof(*q->desc),
992991
&dma_addr, GFP_KERNEL);
993992
if (!q->desc)
994993
return -ENOMEM;
995994

996-
for (i = 0; i < q->ndesc; i++) {
995+
for (i = 0; i < size; i++) {
997996
u32 val = FIELD_PREP(QDMA_DESC_DONE_MASK, 1);
998997

999998
list_add_tail(&q->entry[i].list, &q->tx_list);
1000999
WRITE_ONCE(q->desc[i].ctrl, cpu_to_le32(val));
10011000
}
1001+
q->ndesc = size;
10021002

10031003
/* xmit ring drop default setting */
10041004
airoha_qdma_set(qdma, REG_TX_RING_BLOCKING(qid),

0 commit comments

Comments
 (0)