]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drm/prime: drop reference on imported dma-buf come from gem
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 27 Sep 2012 06:30:06 +0000 (15:30 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jan 2013 16:46:11 +0000 (08:46 -0800)
commit be8a42ae60addd8b6092535c11b42d099d6470ec upstream.

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 <sw0312.kim@samsung.com>
Signed-off-by: Kyungmin.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>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
drivers/gpu/drm/i915/i915_gem_dmabuf.c
drivers/gpu/drm/nouveau/nouveau_prime.c
drivers/gpu/drm/radeon/radeon_prime.c
drivers/staging/omapdrm/omap_gem_dmabuf.c

index fae1f2ec886c5f824d493f669347eb35ae967041..f2b2f019b708417fa600d22c15784d82cf503f8c 100644 (file)
@@ -210,7 +210,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;
                }
        }
index 7be4241e824263efb8116533b680738ef74d449e..abeaafef6d7ef9986313be7ab8e0c2c5a992c065 100644 (file)
@@ -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;
                }
        }
index 366462cf8a2cdfb9ed679398d15476bd40a35695..4f604cd9da1a8c98c456b1ddc691db340fa11af8 100644 (file)
@@ -197,6 +197,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;
                        }
                }
index e09521858f64469cf51b7c8700576d5b6744998e..26c23bb651c6b53835a2061096bdecd4f9d47492 100644 (file)
@@ -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;
                }
        }
index c6f3ef6f57b9671e1dd18cc158faa831442895b4..784fa4d5860c0c7d70560ffea8f6efed23b204dc 100644 (file)
@@ -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;
                }
        }