From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Vetter Subject: Re: [PATCH 2/2] drm: prime: fix refcounting on the dmabuf import error path Date: Wed, 24 Apr 2013 17:21:54 +0200 Message-ID: <20130424152154.GU6169@phenom.ffwll.local> References: <1366333916-31695-1-git-send-email-airlied@gmail.com> <1366333916-31695-2-git-send-email-airlied@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com [74.125.83.53]) by gabe.freedesktop.org (Postfix) with ESMTP id 4259DE5CB0 for ; Wed, 24 Apr 2013 08:18:53 -0700 (PDT) Received: by mail-ee0-f53.google.com with SMTP id d17so796442eek.26 for ; Wed, 24 Apr 2013 08:18:52 -0700 (PDT) Content-Disposition: inline In-Reply-To: <1366333916-31695-2-git-send-email-airlied@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: Dave Airlie Cc: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org On Fri, Apr 19, 2013 at 11:11:56AM +1000, Dave Airlie wrote: > From: Imre Deak > > In commit be8a42ae60 we inroduced a refcount problem, where on the > drm_gem_prime_fd_to_handle() error path we'll call dma_buf_put() for > self imported dma buffers. > > Fix this by taking a reference on the dma buffer in the .gem_import > hook instead of assuming the caller had taken one. Besides fixing the > bug this is also more logical. > > Signed-off-by: Imre Deak > Signed-off-by: Dave Airlie Reviewed-by: Daniel Vetter > --- > drivers/gpu/drm/drm_prime.c | 8 +++++++- > drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 4 +++- > drivers/gpu/drm/i915/i915_gem_dmabuf.c | 5 ++++- > drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c | 1 - > drivers/gpu/drm/udl/udl_gem.c | 4 ++++ > 5 files changed, 18 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c > index eb7c38d..71f02ff 100644 > --- a/drivers/gpu/drm/drm_prime.c > +++ b/drivers/gpu/drm/drm_prime.c > @@ -276,7 +276,6 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, > * refcount on gem itself instead of f_count of dmabuf. > */ > drm_gem_object_reference(obj); > - dma_buf_put(dma_buf); > return obj; > } > } > @@ -285,6 +284,8 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, > if (IS_ERR(attach)) > return ERR_PTR(PTR_ERR(attach)); > > + get_dma_buf(dma_buf); > + > sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL); > if (IS_ERR_OR_NULL(sgt)) { > ret = PTR_ERR(sgt); > @@ -305,6 +306,8 @@ fail_unmap: > dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL); > fail_detach: > dma_buf_detach(dma_buf, attach); > + dma_buf_put(dma_buf); > + > return ERR_PTR(ret); > } > EXPORT_SYMBOL(drm_gem_prime_import); > @@ -347,6 +350,9 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, > goto fail; > > mutex_unlock(&file_priv->prime.lock); > + > + dma_buf_put(dma_buf); > + > return 0; > > fail: > diff --git a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c > index ba0a3aa..ff7f2a8 100644 > --- a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c > +++ b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c > @@ -235,7 +235,6 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev, > * refcount on gem itself instead of f_count of dmabuf. > */ > drm_gem_object_reference(obj); > - dma_buf_put(dma_buf); > return obj; > } > } > @@ -244,6 +243,7 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev, > if (IS_ERR(attach)) > return ERR_PTR(-EINVAL); > > + get_dma_buf(dma_buf); > > sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL); > if (IS_ERR_OR_NULL(sgt)) { > @@ -298,6 +298,8 @@ err_unmap_attach: > dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL); > err_buf_detach: > dma_buf_detach(dma_buf, attach); > + dma_buf_put(dma_buf); > + > return ERR_PTR(ret); > } > > diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c > index 6a5af68..c303de1 100644 > --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c > +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c > @@ -271,7 +271,6 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, > * refcount on gem itself instead of f_count of dmabuf. > */ > drm_gem_object_reference(&obj->base); > - dma_buf_put(dma_buf); > return &obj->base; > } > } > @@ -281,6 +280,8 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, > if (IS_ERR(attach)) > return ERR_CAST(attach); > > + get_dma_buf(dma_buf); > + > obj = i915_gem_object_alloc(dev); > if (obj == NULL) { > ret = -ENOMEM; > @@ -300,5 +301,7 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, > > fail_detach: > dma_buf_detach(dma_buf, attach); > + dma_buf_put(dma_buf); > + > return ERR_PTR(ret); > } > diff --git a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c > index ac74d1b..1bdf7e1 100644 > --- a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c > +++ b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c > @@ -212,7 +212,6 @@ struct drm_gem_object *omap_gem_prime_import(struct drm_device *dev, > * refcount on gem itself instead of f_count of dmabuf. > */ > drm_gem_object_reference(obj); > - dma_buf_put(buffer); > return obj; > } > } > diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c > index 3816270..ef034fa 100644 > --- a/drivers/gpu/drm/udl/udl_gem.c > +++ b/drivers/gpu/drm/udl/udl_gem.c > @@ -303,6 +303,8 @@ struct drm_gem_object *udl_gem_prime_import(struct drm_device *dev, > if (IS_ERR(attach)) > return ERR_CAST(attach); > > + get_dma_buf(dma_buf); > + > sg = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL); > if (IS_ERR(sg)) { > ret = PTR_ERR(sg); > @@ -322,5 +324,7 @@ fail_unmap: > dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL); > fail_detach: > dma_buf_detach(dma_buf, attach); > + dma_buf_put(dma_buf); > + > return ERR_PTR(ret); > } > -- > 1.8.2 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/dri-devel -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch