In mvpp2_rxq_init(), if xdp_rxq_info_reg() or xdp_rxq_info_reg_mem_model() fails after dma_alloc_coherent() has succeeded, the err_free_dma unwind path calls dma_free_coherent() for rxq->descs without resetting rxq->descs to NULL or rxq->descs_dma to 0. On error return from mvpp2_rxq_init(), mvpp2_setup_rxqs() jumps to err_cleanup and calls mvpp2_cleanup_rxqs() -> mvpp2_rxq_deinit(). Because rxq->descs is still non-NULL on the failing queue, mvpp2_rxq_deinit() invokes dma_free_coherent() a second time on the already-freed DMA allocation: DMA-API: platform mvpp2_repro: device driver tries to free DMA memory it has not allocated [size=512 bytes] Call Trace: check_unmap debug_dma_free_coherent dma_free_attrs mvpp2_cleanup_rxqs mvpp2_setup_rxqs Clear rxq->descs and rxq->descs_dma after freeing them on the error path of mvpp2_rxq_init() so subsequent cleanup in mvpp2_rxq_deinit() skips the already-freed descriptor ring. Fixes: b27db2274ba8 ("mvpp2: use page_pool allocator") Cc: stable@vger.kernel.org Signed-off-by: Yuansheng Yang <0xbeac@gmail.com> --- Compiled drivers/net/ethernet/marvell/mvpp2/mvpp2_main.o with W=1 on x86_64 (0 warnings, 0 errors) and verified on v7.4-rc5 in an x86_64 KASAN + DMA-API debug QEMU guest via mvpp2_setup_rxqs() failing XDP memory model registration followed by mvpp2_cleanup_rxqs(): before this fix, DMA-API reports freeing unallocated DMA memory in mvpp2_cleanup_rxqs(); after this fix, 10/10 iterations unwind cleanly with rxq->descs == NULL and 0 DMA-API, KASAN, BUG, or WARNING diagnostics. drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c index 35adcee9a..1dfefd355 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -3021,6 +3021,8 @@ static int mvpp2_rxq_init(struct mvpp2_port *port, dma_free_coherent(port->dev->dev.parent, rxq->size * MVPP2_DESC_ALIGNED_SIZE, rxq->descs, rxq->descs_dma); + rxq->descs = NULL; + rxq->descs_dma = 0; return err; } -- 2.53.0