Skip to content

Commit 75065d7

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 5e5def7 commit 75065d7

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
@@ -163,7 +163,8 @@ static void ion_buffer_kmap_put(struct ion_buffer *buffer)
163163
}
164164
}
165165

166-
static struct sg_table *dup_sg_table(struct sg_table *table)
166+
static struct sg_table *dup_sg_table(struct sg_table *table,
167+
bool preserve_dma_address)
167168
{
168169
struct sg_table *new_table;
169170
int ret, i;
@@ -182,7 +183,8 @@ static struct sg_table *dup_sg_table(struct sg_table *table)
182183
new_sg = new_table->sgl;
183184
for_each_sg(table->sgl, sg, table->nents, i) {
184185
memcpy(new_sg, sg, sizeof(*sg));
185-
new_sg->dma_address = 0;
186+
if (!preserve_dma_address)
187+
new_sg->dma_address = 0;
186188
new_sg = sg_next(new_sg);
187189
}
188190

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

216-
table = dup_sg_table(buffer->sg_table);
218+
if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
219+
a->no_map = true;
220+
221+
table = dup_sg_table(buffer->sg_table, a->no_map);
217222
if (IS_ERR(table)) {
218223
kfree(a);
219224
return -ENOMEM;
220225
}
221226

222-
if (buffer->heap->type == ION_HEAP_TYPE_UNMAPPED)
223-
a->no_map = true;
224-
225227
a->table = table;
226228
a->dev = dev;
227229
INIT_LIST_HEAD(&a->list);

0 commit comments

Comments
 (0)