I am rolling back in reverse order here, so I think we first need
On 06/12/2018 09:42 AM, Oleksandr Andrushchenko wrote:
 int gntdev_dmabuf_imp_release(struct gntdev_dmabuf_priv *priv, u32 fd)
 {
-ÂÂÂ return -EINVAL;
+ÂÂÂ struct gntdev_dmabuf *gntdev_dmabuf;
+ÂÂÂ struct dma_buf_attachment *attach;
+ÂÂÂ struct dma_buf *dma_buf;
+
+ÂÂÂ gntdev_dmabuf = dmabuf_imp_find_unlink(priv, fd);
+ÂÂÂ if (IS_ERR(gntdev_dmabuf))
+ÂÂÂÂÂÂÂ return PTR_ERR(gntdev_dmabuf);
+
+ÂÂÂ pr_debug("Releasing DMA buffer with fd %d\n", fd);
+
+ÂÂÂ attach = gntdev_dmabuf->u.imp.attach;
+
+ÂÂÂ if (gntdev_dmabuf->u.imp.sgt)
+ÂÂÂÂÂÂÂ dma_buf_unmap_attachment(attach, gntdev_dmabuf->u.imp.sgt,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ DMA_BIDIRECTIONAL);
+ÂÂÂ dma_buf = attach->dmabuf;
+ÂÂÂ dma_buf_detach(attach->dmabuf, attach);
+ÂÂÂ dma_buf_put(dma_buf);
+
+ÂÂÂ dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ gntdev_dmabuf->nr_pages);
Should you first end foreign access, before doing anything?
-boris
+ dmabuf_imp_free_storage(gntdev_dmabuf);
+ÂÂÂ return 0;
 }