Skip to content

Commit f4544e5

Browse files
Tom Rixdavem330
authored andcommitted
net: mvneta: fix double free of txq->buf
clang static analysis reports this problem: drivers/net/ethernet/marvell/mvneta.c:3465:2: warning: Attempt to free released memory kfree(txq->buf); ^~~~~~~~~~~~~~~ When mvneta_txq_sw_init() fails to alloc txq->tso_hdrs, it frees without poisoning txq->buf. The error is caught in the mvneta_setup_txqs() caller which handles the error by cleaning up all of the txqs with a call to mvneta_txq_sw_deinit which also frees txq->buf. Since mvneta_txq_sw_deinit is a general cleaner, all of the partial cleaning in mvneta_txq_sw_deinit()'s error handling is not needed. Fixes: 2adb719 ("net: mvneta: Implement software TSO") Signed-off-by: Tom Rix <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 580e427 commit f4544e5

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

drivers/net/ethernet/marvell/mvneta.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,24 +3400,15 @@ static int mvneta_txq_sw_init(struct mvneta_port *pp,
34003400
txq->last_desc = txq->size - 1;
34013401

34023402
txq->buf = kmalloc_array(txq->size, sizeof(*txq->buf), GFP_KERNEL);
3403-
if (!txq->buf) {
3404-
dma_free_coherent(pp->dev->dev.parent,
3405-
txq->size * MVNETA_DESC_ALIGNED_SIZE,
3406-
txq->descs, txq->descs_phys);
3403+
if (!txq->buf)
34073404
return -ENOMEM;
3408-
}
34093405

34103406
/* Allocate DMA buffers for TSO MAC/IP/TCP headers */
34113407
txq->tso_hdrs = dma_alloc_coherent(pp->dev->dev.parent,
34123408
txq->size * TSO_HEADER_SIZE,
34133409
&txq->tso_hdrs_phys, GFP_KERNEL);
3414-
if (!txq->tso_hdrs) {
3415-
kfree(txq->buf);
3416-
dma_free_coherent(pp->dev->dev.parent,
3417-
txq->size * MVNETA_DESC_ALIGNED_SIZE,
3418-
txq->descs, txq->descs_phys);
3410+
if (!txq->tso_hdrs)
34193411
return -ENOMEM;
3420-
}
34213412

34223413
/* Setup XPS mapping */
34233414
if (txq_number > 1)

0 commit comments

Comments
 (0)