Skip to content

Commit

Permalink
drm/prime: drop reference on imported dma-buf come from gem
Browse files Browse the repository at this point in the history
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: Seung-Woo Kim <[email protected]>
Signed-off-by: Kyungmin.park <[email protected]>
Cc: Inki Dae <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: Rob Clark <[email protected]>
Cc: Alex Deucher <[email protected]>
Cc: stable <[email protected]>
Signed-off-by: Dave Airlie <[email protected]>
  • Loading branch information
devusr-sw-kim authored and airlied committed Jan 8, 2013
1 parent f3215be commit be8a42a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev,

/* is it from our device? */
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);
dma_buf_put(dma_buf);
return obj;
}
}
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/i915/i915_gem_dmabuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,12 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
obj = dma_buf->priv;
/* is it from our device? */
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);
dma_buf_put(dma_buf);
return &obj->base;
}
}
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/nouveau/nouveau_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ struct drm_gem_object *nouveau_gem_prime_import(struct drm_device *dev,
if (nvbo->gem) {
if (nvbo->gem->dev == dev) {
drm_gem_object_reference(nvbo->gem);
dma_buf_put(dma_buf);
return nvbo->gem;
}
}
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/radeon/radeon_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ struct drm_gem_object *radeon_gem_prime_import(struct drm_device *dev,
bo = dma_buf->priv;
if (bo->gem_base.dev == dev) {
drm_gem_object_reference(&bo->gem_base);
dma_buf_put(dma_buf);
return &bo->gem_base;
}
}
Expand Down
5 changes: 5 additions & 0 deletions drivers/staging/omapdrm/omap_gem_dmabuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ struct drm_gem_object *omap_gem_prime_import(struct drm_device *dev,
obj = buffer->priv;
/* is it from our device? */
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);
dma_buf_put(buffer);
return obj;
}
}
Expand Down

0 comments on commit be8a42a

Please sign in to comment.