Skip to content

Commit 9823b25

Browse files
jforissieretienne-lms
authored andcommitted
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]> Tested-by: Jerome Forissier <[email protected]> (HiKey960, SDP) Tested-by: Etienne Carriere <[email protected]> (Qemu_v7/v8, SDP)
1 parent 17774a5 commit 9823b25

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
@@ -171,7 +171,8 @@ static void ion_buffer_kmap_put(struct ion_buffer *buffer)
171171
}
172172
}
173173

174-
static struct sg_table *dup_sg_table(struct sg_table *table)
174+
static struct sg_table *dup_sg_table(struct sg_table *table,
175+
bool preserve_dma_address)
175176
{
176177
struct sg_table *new_table;
177178
int ret, i;
@@ -190,7 +191,8 @@ static struct sg_table *dup_sg_table(struct sg_table *table)
190191
new_sg = new_table->sgl;
191192
for_each_sg(table->sgl, sg, table->nents, i) {
192193
memcpy(new_sg, sg, sizeof(*sg));
193-
new_sg->dma_address = 0;
194+
if (!preserve_dma_address)
195+
new_sg->dma_address = 0;
194196
new_sg = sg_next(new_sg);
195197
}
196198

@@ -221,15 +223,15 @@ static int ion_dma_buf_attach(struct dma_buf *dmabuf,
221223
if (!a)
222224
return -ENOMEM;
223225

224-
table = dup_sg_table(buffer->sg_table);
226+
if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
227+
a->no_map = true;
228+
229+
table = dup_sg_table(buffer->sg_table, a->no_map);
225230
if (IS_ERR(table)) {
226231
kfree(a);
227232
return -ENOMEM;
228233
}
229234

230-
if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
231-
a->no_map = true;
232-
233235
a->table = table;
234236
a->dev = attachment->dev;
235237
INIT_LIST_HEAD(&a->list);

0 commit comments

Comments
 (0)