diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index de5db82978b913..095a031565e9a6 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -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; @@ -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); } @@ -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);