Skip to content

Commit

Permalink
dmaengine: sun4i: fix unsafe list iteration
Browse files Browse the repository at this point in the history
Currently, sun4i_dma_free_contract iterates over lists and frees memory
as it goes through them, causing reads to recently freed memory to
be performed. Fix this by using the safe version of the iterator, so
freed memory is not referenced at all.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Emilio López <emilio@elopez.com.ar>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
  • Loading branch information
Emilio López authored and Vinod Koul committed Sep 30, 2015
1 parent 0b23a1e commit 40482e6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/dma/sun4i-dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,13 @@ get_next_cyclic_promise(struct sun4i_dma_contract *contract)
static void sun4i_dma_free_contract(struct virt_dma_desc *vd)
{
struct sun4i_dma_contract *contract = to_sun4i_dma_contract(vd);
struct sun4i_dma_promise *promise;
struct sun4i_dma_promise *promise, *tmp;

/* Free all the demands and completed demands */
list_for_each_entry(promise, &contract->demands, list)
list_for_each_entry_safe(promise, tmp, &contract->demands, list)
kfree(promise);

list_for_each_entry(promise, &contract->completed_demands, list)
list_for_each_entry_safe(promise, tmp, &contract->completed_demands, list)
kfree(promise);

kfree(contract);
Expand Down

0 comments on commit 40482e6

Please sign in to comment.