Commit be8a42ae authored by Seung-Woo Kim's avatar Seung-Woo Kim Committed by Dave Airlie

drm/prime: drop reference on imported dma-buf come from gem

Increasing ref counts of both dma-buf and gem for imported dma-buf come from gem
makes memory leak. release function of dma-buf cannot be called because f_count
of dma-buf increased by importing gem and gem ref count cannot be decrease
because of exported dma-buf.

So I add dma_buf_put() for imported gem come from its own gem into each drivers
having prime_import and prime_export capabilities. With this, only gem ref
count is increased if importing gem exported from gem of same driver.
Signed-off-by: default avatarSeung-Woo Kim <sw0312.kim@samsung.com>
Signed-off-by: default avatarKyungmin.park <kyungmin.park@samsung.com>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Rob Clark <rob.clark@linaro.org>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent f3215be9
...@@ -232,7 +232,12 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev, ...@@ -232,7 +232,12 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev,
/* is it from our device? */ /* is it from our device? */
if (obj->dev == drm_dev) { if (obj->dev == drm_dev) {
/*
* Importing dmabuf exported from out own gem increases
* refcount on gem itself instead of f_count of dmabuf.
*/
drm_gem_object_reference(obj); drm_gem_object_reference(obj);
dma_buf_put(dma_buf);
return obj; return obj;
} }
} }
......
...@@ -266,7 +266,12 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, ...@@ -266,7 +266,12 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
obj = dma_buf->priv; obj = dma_buf->priv;
/* is it from our device? */ /* is it from our device? */
if (obj->base.dev == dev) { if (obj->base.dev == dev) {
/*
* Importing dmabuf exported from out own gem increases
* refcount on gem itself instead of f_count of dmabuf.
*/
drm_gem_object_reference(&obj->base); drm_gem_object_reference(&obj->base);
dma_buf_put(dma_buf);
return &obj->base; return &obj->base;
} }
} }
......
...@@ -193,6 +193,7 @@ struct drm_gem_object *nouveau_gem_prime_import(struct drm_device *dev, ...@@ -193,6 +193,7 @@ struct drm_gem_object *nouveau_gem_prime_import(struct drm_device *dev,
if (nvbo->gem) { if (nvbo->gem) {
if (nvbo->gem->dev == dev) { if (nvbo->gem->dev == dev) {
drm_gem_object_reference(nvbo->gem); drm_gem_object_reference(nvbo->gem);
dma_buf_put(dma_buf);
return nvbo->gem; return nvbo->gem;
} }
} }
......
...@@ -194,6 +194,7 @@ struct drm_gem_object *radeon_gem_prime_import(struct drm_device *dev, ...@@ -194,6 +194,7 @@ struct drm_gem_object *radeon_gem_prime_import(struct drm_device *dev,
bo = dma_buf->priv; bo = dma_buf->priv;
if (bo->gem_base.dev == dev) { if (bo->gem_base.dev == dev) {
drm_gem_object_reference(&bo->gem_base); drm_gem_object_reference(&bo->gem_base);
dma_buf_put(dma_buf);
return &bo->gem_base; return &bo->gem_base;
} }
} }
......
...@@ -207,7 +207,12 @@ struct drm_gem_object *omap_gem_prime_import(struct drm_device *dev, ...@@ -207,7 +207,12 @@ struct drm_gem_object *omap_gem_prime_import(struct drm_device *dev,
obj = buffer->priv; obj = buffer->priv;
/* is it from our device? */ /* is it from our device? */
if (obj->dev == dev) { if (obj->dev == dev) {
/*
* Importing dmabuf exported from out own gem increases
* refcount on gem itself instead of f_count of dmabuf.
*/
drm_gem_object_reference(obj); drm_gem_object_reference(obj);
dma_buf_put(buffer);
return obj; return obj;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment