Skip to content

Commit 3790509

Browse files
LorenzoBianconiPaolo Abeni
authored andcommitted
net: airoha: Move ndesc initialization at end of airoha_qdma_init_rx_queue()
If queue entry or DMA descriptor list allocation fails in airoha_qdma_init_rx_queue routine, airoha_qdma_cleanup() will trigger a NULL pointer dereference running netif_napi_del() for RX queue NAPIs since netif_napi_add() has never been executed to this particular RX NAPI. The issue is due to the early ndesc initialization in airoha_qdma_init_rx_queue() since airoha_qdma_cleanup() relies on ndesc value to check if the queue is properly initialized. Fix the issue moving ndesc initialization at end of airoha_qdma_init_tx routine. Move page_pool allocation after descriptor list allocation in order to avoid memory leaks if desc allocation fails. Fixes: 23020f0 ("net: airoha: Introduce ethernet support for EN7581 SoC") Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Link: https://patch.msgid.link/20260420-airoha_qdma_init_rx_queue-fix-v2-1-d99347e5c18d@kernel.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 7dddc74 commit 3790509

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

drivers/net/ethernet/airoha/airoha_eth.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -745,14 +745,18 @@ static int airoha_qdma_init_rx_queue(struct airoha_queue *q,
745745
dma_addr_t dma_addr;
746746

747747
q->buf_size = PAGE_SIZE / 2;
748-
q->ndesc = ndesc;
749748
q->qdma = qdma;
750749

751-
q->entry = devm_kzalloc(eth->dev, q->ndesc * sizeof(*q->entry),
750+
q->entry = devm_kzalloc(eth->dev, ndesc * sizeof(*q->entry),
752751
GFP_KERNEL);
753752
if (!q->entry)
754753
return -ENOMEM;
755754

755+
q->desc = dmam_alloc_coherent(eth->dev, ndesc * sizeof(*q->desc),
756+
&dma_addr, GFP_KERNEL);
757+
if (!q->desc)
758+
return -ENOMEM;
759+
756760
q->page_pool = page_pool_create(&pp_params);
757761
if (IS_ERR(q->page_pool)) {
758762
int err = PTR_ERR(q->page_pool);
@@ -761,11 +765,7 @@ static int airoha_qdma_init_rx_queue(struct airoha_queue *q,
761765
return err;
762766
}
763767

764-
q->desc = dmam_alloc_coherent(eth->dev, q->ndesc * sizeof(*q->desc),
765-
&dma_addr, GFP_KERNEL);
766-
if (!q->desc)
767-
return -ENOMEM;
768-
768+
q->ndesc = ndesc;
769769
netif_napi_add(eth->napi_dev, &q->napi, airoha_qdma_rx_napi_poll);
770770

771771
airoha_qdma_wr(qdma, REG_RX_RING_BASE(qid), dma_addr);

0 commit comments

Comments
 (0)