Skip to content

Commit

Permalink
staging: android: ion: do not clear dma_address of unmapped heap
Browse files Browse the repository at this point in the history
Since commit 54ef5b9 (staging: android: ion: Initialize dma_address
of new sg list") (Linux v4.17), the helper function dup_sg_table() called
by ion_dma_buf_attach() does not preserve the dma_address from the
original SG list. It is a problem for the unmapped heap, because
dma_buf_attach() followed by dma_buf_map_attachment() now returns a SG
table with NULL dma_address, which breaks tee_shm_register_fd().

This commit avoids the dma_address reset for the unmapped heap.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
  • Loading branch information
jforissier committed Aug 31, 2018
1 parent 5e5def7 commit 75065d7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/staging/android/ion/ion.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ static void ion_buffer_kmap_put(struct ion_buffer *buffer)
}
}

static struct sg_table *dup_sg_table(struct sg_table *table)
static struct sg_table *dup_sg_table(struct sg_table *table,
bool preserve_dma_address)
{
struct sg_table *new_table;
int ret, i;
Expand All @@ -182,7 +183,8 @@ static struct sg_table *dup_sg_table(struct sg_table *table)
new_sg = new_table->sgl;
for_each_sg(table->sgl, sg, table->nents, i) {
memcpy(new_sg, sg, sizeof(*sg));
new_sg->dma_address = 0;
if (!preserve_dma_address)
new_sg->dma_address = 0;
new_sg = sg_next(new_sg);
}

Expand Down Expand Up @@ -213,15 +215,15 @@ static int ion_dma_buf_attach(struct dma_buf *dmabuf, struct device *dev,
if (!a)
return -ENOMEM;

table = dup_sg_table(buffer->sg_table);
if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
a->no_map = true;

table = dup_sg_table(buffer->sg_table, a->no_map);
if (IS_ERR(table)) {
kfree(a);
return -ENOMEM;
}

if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
a->no_map = true;

a->table = table;
a->dev = dev;
INIT_LIST_HEAD(&a->list);
Expand Down

0 comments on commit 75065d7

Please sign in to comment.