Skip to content

Commit 98f5f93

Browse files
rgenoudvinodkoul
authored andcommitted
dmaengine: at_hdmac: fix memory leak in at_dma_xlate()
The leak was found when opening/closing a serial port a great number of time, increasing kmalloc-32 in slabinfo. Each time the port was opened, dma_request_slave_channel() was called. Then, in at_dma_xlate(), atslave was allocated with devm_kzalloc() and never freed. (Well, it was free at module unload, but that's not what we want). So, here, kzalloc is more suited for the job since it has to be freed in atc_free_chan_resources(). Cc: stable@vger.kernel.org Fixes: bbe89c8 ("at_hdmac: move to generic DMA binding") Reported-by: Mario Forner <m.forner@be4energy.com> Suggested-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com> Signed-off-by: Richard Genoud <richard.genoud@gmail.com> Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 6510223 commit 98f5f93

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/dma/at_hdmac.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,12 @@ static void atc_free_chan_resources(struct dma_chan *chan)
16411641
atchan->descs_allocated = 0;
16421642
atchan->status = 0;
16431643

1644+
/*
1645+
* Free atslave allocated in at_dma_xlate()
1646+
*/
1647+
kfree(chan->private);
1648+
chan->private = NULL;
1649+
16441650
dev_vdbg(chan2dev(chan), "free_chan_resources: done\n");
16451651
}
16461652

@@ -1675,7 +1681,7 @@ static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec,
16751681
dma_cap_zero(mask);
16761682
dma_cap_set(DMA_SLAVE, mask);
16771683

1678-
atslave = devm_kzalloc(&dmac_pdev->dev, sizeof(*atslave), GFP_KERNEL);
1684+
atslave = kzalloc(sizeof(*atslave), GFP_KERNEL);
16791685
if (!atslave)
16801686
return NULL;
16811687

0 commit comments

Comments
 (0)