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

Commit 3cc2a013 authored by Zhenhua Huang's avatar Zhenhua Huang
Browse files

ion: Do not do allocation if the size exceeding heap remaining



There is no need to do the allocation if the size exceeding heap
remaining as it is surely not be successful. The other effect
is we should not pool the pages to fullfill heap.

Change-Id: I5fc32254e428c915a1dd6ce5839bc6ba8085dfdb
Signed-off-by: default avatarZhenhua Huang <zhenhuah@codeaurora.org>
parent 179ee912
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -562,6 +562,7 @@ static struct ion_secure_cma_buffer_info *__ion_secure_cma_allocate_non_contig(
	unsigned long ncelems = 0;
	struct scatterlist *sg;
	unsigned long total_allocated = 0;
	unsigned long total_added_to_pool = 0;

	dev_dbg(sheap->dev, "Request buffer allocation len %ld\n", len);

@@ -599,6 +600,7 @@ static struct ion_secure_cma_buffer_info *__ion_secure_cma_allocate_non_contig(
				kfree(nc_info);
				continue;
			}
			total_added_to_pool += alloc_size;
			ret = ion_secure_cma_alloc_from_pool(sheap,
							     &nc_info->phys,
							     alloc_size);
@@ -650,6 +652,11 @@ static struct ion_secure_cma_buffer_info *__ion_secure_cma_allocate_non_contig(
err1:
	__ion_secure_cma_free_non_contig(sheap, info);
	kfree(info->table);
	/*
	 * There may be a concurrent case that entering this function
	 * although remaining heap not enough
	 */
	__ion_secure_cma_shrink_pool(sheap, total_added_to_pool);
err:
	kfree(info);
	return ION_CMA_ALLOCATE_FAILED;
@@ -663,6 +670,8 @@ static int ion_secure_cma_allocate(struct ion_heap *heap,
	unsigned long secure_allocation = flags & ION_FLAG_SECURE;
	struct ion_secure_cma_buffer_info *buf = NULL;
	unsigned long allow_non_contig = flags & ION_FLAG_ALLOW_NON_CONTIG;
	struct ion_cma_secure_heap *sheap =
			container_of(heap, struct ion_cma_secure_heap, heap);

	if (!secure_allocation &&
	    !ion_heap_allow_secure_allocation(heap->type)) {
@@ -686,6 +695,9 @@ static int ion_secure_cma_allocate(struct ion_heap *heap,
	if (!allow_non_contig)
		buf = __ion_secure_cma_allocate(heap, buffer, len, align,
						flags);
	else if (len > (sheap->heap_size - atomic_read(&sheap->
			total_allocated) - atomic_read(&sheap->total_leaked)))
		return -ENOMEM;
	else
		buf = __ion_secure_cma_allocate_non_contig(heap, buffer, len,
							   align, flags);