Skip to content

Commit a12f37e

Browse files
committed
staging: android: ion: do not clear dma_address of unmapped heap
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 <[email protected]>
1 parent 7321b45 commit a12f37e

File tree

1 file changed

+8
-6
lines changed
  • drivers/staging/android/ion

1 file changed

+8
-6
lines changed

drivers/staging/android/ion/ion.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ static void ion_buffer_kmap_put(struct ion_buffer *buffer)
174174
}
175175
}
176176

177-
static struct sg_table *dup_sg_table(struct sg_table *table)
177+
static struct sg_table *dup_sg_table(struct sg_table *table,
178+
bool preserve_dma_address)
178179
{
179180
struct sg_table *new_table;
180181
int ret, i;
@@ -193,7 +194,8 @@ static struct sg_table *dup_sg_table(struct sg_table *table)
193194
new_sg = new_table->sgl;
194195
for_each_sg(table->sgl, sg, table->nents, i) {
195196
memcpy(new_sg, sg, sizeof(*sg));
196-
new_sg->dma_address = 0;
197+
if (!preserve_dma_address)
198+
new_sg->dma_address = 0;
197199
new_sg = sg_next(new_sg);
198200
}
199201

@@ -224,15 +226,15 @@ static int ion_dma_buf_attach(struct dma_buf *dmabuf,
224226
if (!a)
225227
return -ENOMEM;
226228

227-
table = dup_sg_table(buffer->sg_table);
229+
if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
230+
a->no_map = true;
231+
232+
table = dup_sg_table(buffer->sg_table, a->no_map);
228233
if (IS_ERR(table)) {
229234
kfree(a);
230235
return -ENOMEM;
231236
}
232237

233-
if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
234-
a->no_map = true;
235-
236238
a->table = table;
237239
a->dev = attachment->dev;
238240
INIT_LIST_HEAD(&a->list);

0 commit comments

Comments
 (0)