drm/prime: fix to put an exported dma_buf for adding handle failure
authorYoungJun Cho <yj44.cho@samsung.com>
Wed, 26 Jun 2013 01:21:40 +0000 (10:21 +0900)
committerDave Airlie <airlied@redhat.com>
Fri, 28 Jun 2013 02:49:07 +0000 (12:49 +1000)
When drm_prime_add_buf_handle() returns failure for an exported
dma_buf, the dma_buf was already allocated and its refcount was
increased, so it needs to be put.

Signed-off-by: YoungJun Cho <yj44.cho@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_prime.c

index b1cd47438850ef729f444da334f045b10170d7c8..340caabc04246c3e4d1a0034b37ae76ec8e88bde 100644 (file)
@@ -306,7 +306,7 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,
        ret = drm_prime_add_buf_handle(&file_priv->prime,
                                       obj->export_dma_buf, handle);
        if (ret)
-               goto out;
+               goto fail_put_dmabuf;
 
        *prime_fd = dma_buf_fd(buf, flags);
        mutex_unlock(&file_priv->prime.lock);
@@ -315,6 +315,12 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev,
 out_have_obj:
        get_dma_buf(dmabuf);
        *prime_fd = dma_buf_fd(dmabuf, flags);
+       goto out;
+
+fail_put_dmabuf:
+       /* clear NOT to be checked when releasing dma_buf */
+       obj->export_dma_buf = NULL;
+       dma_buf_put(buf);
 out:
        drm_gem_object_unreference_unlocked(obj);
        mutex_unlock(&file_priv->prime.lock);