diff --git a/drivers/staging/android/ion/ion_dma_buf.c b/drivers/staging/android/ion/ion_dma_buf.c index 1e1236155dea..ee0e81eef0df 100644 --- a/drivers/staging/android/ion/ion_dma_buf.c +++ b/drivers/staging/android/ion/ion_dma_buf.c @@ -69,6 +69,7 @@ static int ion_dma_buf_attach(struct dma_buf *dmabuf, a->table = table; a->dev = attachment->dev; INIT_LIST_HEAD(&a->list); + a->mapped = false; attachment->priv = a; @@ -114,6 +115,8 @@ static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment, if (!dma_map_sg(attachment->dev, table->sgl, table->nents, direction)) return ERR_PTR(-ENOMEM); + a->mapped = true; + return table; } @@ -123,6 +126,9 @@ static void ion_unmap_dma_buf(struct dma_buf_attachment *attachment, { struct ion_buffer *buffer = attachment->dmabuf->priv; struct ion_heap *heap = buffer->heap; + struct ion_dma_buf_attachment *a = attachment->priv; + + a->mapped = false; if (heap->buf_ops.unmap_dma_buf) return heap->buf_ops.unmap_dma_buf(attachment, table, @@ -167,6 +173,8 @@ static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, } list_for_each_entry(a, &buffer->attachments, list) { + if (!a->mapped) + continue; dma_sync_sg_for_cpu(a->dev, a->table->sgl, a->table->nents, direction); } @@ -209,6 +217,8 @@ static int ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, ion_buffer_kmap_put(buffer); list_for_each_entry(a, &buffer->attachments, list) { + if (!a->mapped) + continue; dma_sync_sg_for_device(a->dev, a->table->sgl, a->table->nents, direction); } diff --git a/include/linux/ion.h b/include/linux/ion.h index 4eadf397a6bc..80c6fdeb4822 100644 --- a/include/linux/ion.h +++ b/include/linux/ion.h @@ -156,6 +156,7 @@ struct ion_dma_buf_attachment { struct device *dev; struct sg_table *table; struct list_head list; + bool mapped:1; }; #ifdef CONFIG_ION