Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba2d8d88 authored by Antoine Tenart's avatar Antoine Tenart Committed by David S. Miller
Browse files

net: mvpp2: fix the txq_init error path



When an allocation in the txq_init path fails, the allocated buffers
end-up being freed twice: in the txq_init error path, and in txq_deinit.
This lead to issues as txq_deinit would work on already freed memory
regions:

    kernel BUG at mm/slub.c:3915!
    Internal error: Oops - BUG: 0 [#1] PREEMPT SMP

This patch fixes this by removing the txq_init own error path, as the
txq_deinit function is always called on errors. This was introduced by
TSO as way more buffers are allocated.

Fixes: 186cd4d4 ("net: mvpp2: software tso support")
Signed-off-by: default avatarAntoine Tenart <antoine.tenart@free-electrons.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e2549970
Loading
Loading
Loading
Loading
+2 −18
Original line number Original line Diff line number Diff line
@@ -5805,7 +5805,7 @@ static int mvpp2_txq_init(struct mvpp2_port *port,
						sizeof(*txq_pcpu->buffs),
						sizeof(*txq_pcpu->buffs),
						GFP_KERNEL);
						GFP_KERNEL);
		if (!txq_pcpu->buffs)
		if (!txq_pcpu->buffs)
			goto cleanup;
			return -ENOMEM;


		txq_pcpu->count = 0;
		txq_pcpu->count = 0;
		txq_pcpu->reserved_num = 0;
		txq_pcpu->reserved_num = 0;
@@ -5821,26 +5821,10 @@ static int mvpp2_txq_init(struct mvpp2_port *port,
					   &txq_pcpu->tso_headers_dma,
					   &txq_pcpu->tso_headers_dma,
					   GFP_KERNEL);
					   GFP_KERNEL);
		if (!txq_pcpu->tso_headers)
		if (!txq_pcpu->tso_headers)
			goto cleanup;
			return -ENOMEM;
	}
	}


	return 0;
	return 0;
cleanup:
	for_each_present_cpu(cpu) {
		txq_pcpu = per_cpu_ptr(txq->pcpu, cpu);
		kfree(txq_pcpu->buffs);

		dma_free_coherent(port->dev->dev.parent,
				  txq_pcpu->size * TSO_HEADER_SIZE,
				  txq_pcpu->tso_headers,
				  txq_pcpu->tso_headers_dma);
	}

	dma_free_coherent(port->dev->dev.parent,
			  txq->size * MVPP2_DESC_ALIGNED_SIZE,
			  txq->descs, txq->descs_dma);

	return -ENOMEM;
}
}


/* Free allocated TXQ resources */
/* Free allocated TXQ resources */