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

Commit 1f7ebf5c authored by Suren Baghdasaryan's avatar Suren Baghdasaryan Committed by Gerrit - the friendly Code Review server
Browse files

ion: fix a possible memory leak in ion_cma_allocate



The memory leak occurs when kmalloc() for info->table fails, info is freed
but info->cpu_addr allocation is left.
Fixes: eeeb9407 ("ion: add snapshot of ion support for MSM")

Bug: 130817249
Test: builds and boots

Change-Id: I7faf5be5129a46b2f874f4e3803470e5f5130a21
Reported-by: default avatarMikael Magnusson <Mikael.Magnusson@sony.com>
Suggested-by: default avatarMikael Magnusson <Mikael.Magnusson@sony.com>
Signed-off-by: default avatarSuren Baghdasaryan <surenb@google.com>
Patch: received via email from surenb@google.com @ 04/18/19, 14:42
Signed-off-by: default avatarChetan C R <cravin@codeaurora.org>
parent 4b967be4
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,

	info->table = kmalloc(sizeof(struct sg_table), GFP_KERNEL);
	if (!info->table)
		goto err;
		goto free_mem;

	info->is_cached = ION_IS_CACHED(flags);

@@ -123,6 +123,13 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
	buffer->priv_virt = info;
	return 0;

free_mem:
	if (!ION_IS_CACHED(flags))
		dma_free_writecombine(dev, len, info->cpu_addr, info->handle);
	else
		dma_free_attrs(dev, len, info->cpu_addr, info->handle,
			DMA_ATTR_FORCE_COHERENT);

err:
	kfree(info);
	return ION_CMA_ALLOCATE_FAILED;