Skip to content

Commit 503473a

Browse files
perforVinod Koul
authored andcommitted
dmaengine/ste_dma40: fix memory leak due to prepared descriptors
Prepared descriptors that are not submitted will not be freed. Add prepared descriptor to a list to be able to release them upon dmaengine_terminate_all(). Signed-off-by: Per Forlin <per.forlin@linaro.org> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent 70a207a commit 503473a

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎drivers/dma/ste_dma40.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct d40_base;
177177
* @pending_queue: Submitted jobs, to be issued by issue_pending()
178178
* @active: Active descriptor.
179179
* @queue: Queued jobs.
180+
* @prepare_queue: Prepared jobs.
180181
* @dma_cfg: The client configuration of this dma channel.
181182
* @configured: whether the dma_cfg configuration is valid
182183
* @base: Pointer to the device instance struct.
@@ -204,6 +205,7 @@ struct d40_chan {
204205
struct list_head pending_queue;
205206
struct list_head active;
206207
struct list_head queue;
208+
struct list_head prepare_queue;
207209
struct stedma40_chan_cfg dma_cfg;
208210
bool configured;
209211
struct d40_base *base;
@@ -833,6 +835,13 @@ static void d40_term_all(struct d40_chan *d40c)
833835
d40_desc_free(d40c, d40d);
834836
}
835837

838+
/* Release descriptors in prepare queue */
839+
if (!list_empty(&d40c->prepare_queue))
840+
list_for_each_entry_safe(d40d, _d,
841+
&d40c->prepare_queue, node) {
842+
d40_desc_remove(d40d);
843+
d40_desc_free(d40c, d40d);
844+
}
836845

837846
d40c->pending_tx = 0;
838847
d40c->busy = false;
@@ -1911,6 +1920,12 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src,
19111920
goto err;
19121921
}
19131922

1923+
/*
1924+
* add descriptor to the prepare queue in order to be able
1925+
* to free them later in terminate_all
1926+
*/
1927+
list_add_tail(&desc->node, &chan->prepare_queue);
1928+
19141929
spin_unlock_irqrestore(&chan->lock, flags);
19151930

19161931
return &desc->txd;
@@ -2400,6 +2415,7 @@ static void __init d40_chan_init(struct d40_base *base, struct dma_device *dma,
24002415
INIT_LIST_HEAD(&d40c->queue);
24012416
INIT_LIST_HEAD(&d40c->pending_queue);
24022417
INIT_LIST_HEAD(&d40c->client);
2418+
INIT_LIST_HEAD(&d40c->prepare_queue);
24032419

24042420
tasklet_init(&d40c->tasklet, dma_tasklet,
24052421
(unsigned long) d40c);

0 commit comments

Comments
 (0)