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

Commit 30cafae0 authored by Laura Abbott's avatar Laura Abbott Committed by Shalaj Jain
Browse files

ion: Error out on memory secure failure



All clients have been converted over to the new API
for securing. Instead of silently returning success when
secure fails, error out on a secure failure to allow for proper
error handling.

Change-Id: I57a5c1aef999cfc69a2a9cc1b3e28b2fa74fe3a6
Signed-off-by: default avatarLaura Abbott <lauraa@codeaurora.org>
parent 04cbd09f
Loading
Loading
Loading
Loading
+25 −17
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ struct ion_secure_cma_buffer_info {
	dma_addr_t phys;
	dma_addr_t phys;
	struct sg_table *table;
	struct sg_table *table;
	bool is_cached;
	bool is_cached;
	int len;
};
};


struct ion_cma_alloc_chunk {
struct ion_cma_alloc_chunk {
@@ -480,6 +481,7 @@ retry:
		goto err;
		goto err;
	}
	}


	info->len = len;
	ion_secure_cma_get_sgtable(sheap->dev,
	ion_secure_cma_get_sgtable(sheap->dev,
			info->table, info->phys, len);
			info->table, info->phys, len);


@@ -493,6 +495,17 @@ err:
	return ION_CMA_ALLOCATE_FAILED;
	return ION_CMA_ALLOCATE_FAILED;
}
}


static void __ion_secure_cma_free(struct ion_cma_secure_heap *sheap,
				struct ion_secure_cma_buffer_info *info,
				bool release_memory)
{
	if (release_memory)
		ion_secure_cma_free_from_pool(sheap, info->phys, info->len);
	sg_free_table(info->table);
	kfree(info->table);
	kfree(info);
}

static int ion_secure_cma_allocate(struct ion_heap *heap,
static int ion_secure_cma_allocate(struct ion_heap *heap,
			    struct ion_buffer *buffer,
			    struct ion_buffer *buffer,
			    unsigned long len, unsigned long align,
			    unsigned long len, unsigned long align,
@@ -527,7 +540,7 @@ static int ion_secure_cma_allocate(struct ion_heap *heap,
		int ret;
		int ret;


		if (!msm_secure_v2_is_supported()) {
		if (!msm_secure_v2_is_supported()) {
			pr_debug("%s: securing buffers is not supported on this platform\n",
			pr_err("%s: securing buffers from clients is not supported on this platform\n",
				__func__);
				__func__);
			ret = 1;
			ret = 1;
		} else {
		} else {
@@ -538,21 +551,19 @@ static int ion_secure_cma_allocate(struct ion_heap *heap,
									flags);
									flags);
		}
		}
		if (ret) {
		if (ret) {
			/*
			struct ion_cma_secure_heap *sheap =
			 * Don't treat the secure buffer failing here as an
				container_of(buffer->heap,
			 * error for backwards compatibility reasons. If
					struct ion_cma_secure_heap, heap);
			 * the secure fails, the map will also fail so there

			 * is no security risk.
			pr_err("%s: failed to secure buffer\n", __func__);
			 */
			__ion_secure_cma_free(sheap, buf, true);
			pr_debug("%s: failed to secure buffer\n", __func__);
		}
		}
		return 0;
		return ret;
	} else {
	} else {
		return -ENOMEM;
		return -ENOMEM;
	}
	}
}
}



static void ion_secure_cma_free(struct ion_buffer *buffer)
static void ion_secure_cma_free(struct ion_buffer *buffer)
{
{
	struct ion_cma_secure_heap *sheap =
	struct ion_cma_secure_heap *sheap =
@@ -565,17 +576,14 @@ static void ion_secure_cma_free(struct ion_buffer *buffer)
		ret = msm_ion_unsecure_table(info->table);
		ret = msm_ion_unsecure_table(info->table);
	atomic_sub(buffer->size, &sheap->total_allocated);
	atomic_sub(buffer->size, &sheap->total_allocated);
	BUG_ON(atomic_read(&sheap->total_allocated) < 0);
	BUG_ON(atomic_read(&sheap->total_allocated) < 0);

	/* release memory */
	/* release memory */
	if (!ret) {
	if (ret) {
		ion_secure_cma_free_from_pool(sheap, info->phys, buffer->size);
	} else {
		WARN(1, "Unsecure failed, can't free the memory. Leaking it!");
		WARN(1, "Unsecure failed, can't free the memory. Leaking it!");
		atomic_add(buffer->size, &sheap->total_leaked);
		atomic_add(buffer->size, &sheap->total_leaked);
	}
	}
	/* release sg table */

	sg_free_table(info->table);
	__ion_secure_cma_free(sheap, info, ret ? false : true);
	kfree(info->table);
	kfree(info);
}
}


static int ion_secure_cma_phys(struct ion_heap *heap, struct ion_buffer *buffer,
static int ion_secure_cma_phys(struct ion_heap *heap, struct ion_buffer *buffer,