Skip to content

Commit

Permalink
drm: Take ownership of the dmabuf->obj when exporting
Browse files Browse the repository at this point in the history
Currently the reference for the dmabuf->obj is incremented for the
dmabuf in drm_gem_prime_handle_to_fd() (at the high level userspace
interface), but is released in drm_gem_dmabuf_release() (the lowlevel
handler). Improve the symmetry of the dmabuf->obj ownership by acquiring
the reference in drm_gem_dmabuf_export(). This makes it easier to use
the prime functions directly.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
[danvet: Update kerneldoc.]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20161207214527.22533-1-chris@chris-wilson.co.uk
  • Loading branch information
Chris Wilson authored and Daniel Vetter committed Dec 8, 2016
1 parent f3f4c4d commit 72a93e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 7 additions & 5 deletions drivers/gpu/drm/drm_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach,
*
* This wraps dma_buf_export() for use by generic GEM drivers that are using
* drm_gem_dmabuf_release(). In addition to calling dma_buf_export(), we take
* a reference to the drm_device which is released by drm_gem_dmabuf_release().
* a reference to the &drm_device and the exported &drm_gem_object (stored in
* exp_info->priv) which is released by drm_gem_dmabuf_release().
*
* Returns the new dmabuf.
*/
Expand All @@ -300,8 +301,11 @@ struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,
struct dma_buf *dma_buf;

dma_buf = dma_buf_export(exp_info);
if (!IS_ERR(dma_buf))
drm_dev_ref(dev);
if (IS_ERR(dma_buf))
return dma_buf;

drm_dev_ref(dev);
drm_gem_object_reference(exp_info->priv);

return dma_buf;
}
Expand Down Expand Up @@ -472,8 +476,6 @@ static struct dma_buf *export_and_register_object(struct drm_device *dev,
*/
obj->dma_buf = dmabuf;
get_dma_buf(obj->dma_buf);
/* Grab a new ref since the callers is now used by the dma-buf */
drm_gem_object_reference(obj);

return dmabuf;
}
Expand Down
1 change: 0 additions & 1 deletion drivers/gpu/drm/vgem/vgem_fence.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ static int attach_dmabuf(struct drm_device *dev,
return PTR_ERR(dmabuf);

obj->dma_buf = dmabuf;
drm_gem_object_reference(obj);
return 0;
}

Expand Down

0 comments on commit 72a93e8

Please sign in to comment.