]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
net: mvneta: fix double free of txq->buf
authorTom Rix <trix@redhat.com>
Sat, 3 Oct 2020 18:51:21 +0000 (11:51 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 4 Oct 2020 22:07:19 +0000 (15:07 -0700)
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: 2adb719d74f6 ("net: mvneta: Implement software TSO")
Signed-off-by: Tom Rix <trix@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/marvell/mvneta.c

index c4345e3d616f78589c2b5f59acb0eddb64a177c4..5bf0409f5d42a200f28fc4c4d75f1f9ef96f1afd 100644 (file)
@@ -3400,24 +3400,15 @@ static int mvneta_txq_sw_init(struct mvneta_port *pp,
        txq->last_desc = txq->size - 1;
 
        txq->buf = kmalloc_array(txq->size, sizeof(*txq->buf), GFP_KERNEL);
-       if (!txq->buf) {
-               dma_free_coherent(pp->dev->dev.parent,
-                                 txq->size * MVNETA_DESC_ALIGNED_SIZE,
-                                 txq->descs, txq->descs_phys);
+       if (!txq->buf)
                return -ENOMEM;
-       }
 
        /* Allocate DMA buffers for TSO MAC/IP/TCP headers */
        txq->tso_hdrs = dma_alloc_coherent(pp->dev->dev.parent,
                                           txq->size * TSO_HEADER_SIZE,
                                           &txq->tso_hdrs_phys, GFP_KERNEL);
-       if (!txq->tso_hdrs) {
-               kfree(txq->buf);
-               dma_free_coherent(pp->dev->dev.parent,
-                                 txq->size * MVNETA_DESC_ALIGNED_SIZE,
-                                 txq->descs, txq->descs_phys);
+       if (!txq->tso_hdrs)
                return -ENOMEM;
-       }
 
        /* Setup XPS mapping */
        if (txq_number > 1)