All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 10/10] drm: omapdrm: Take GEM obj and DRM dev references when exporting dmabuf
Date: Fri, 21 Apr 2017 11:49:06 +0300	[thread overview]
Message-ID: <5097550.uOvanFxGd7@avalon> (raw)
In-Reply-To: <20170420230821.GA6793@nuc-i3427.alporthouse.com>

Hi Chris,

On Friday 21 Apr 2017 00:08:21 Chris Wilson wrote:
> On Fri, Apr 21, 2017 at 12:33:59AM +0300, Laurent Pinchart wrote:
> > To ensure that neither the GEM object nor the DRM device goes away while
> > a GEM object exported through dma-buf is still accessible, take a
> > reference to both the GEM object and the DRM device at export time. The
> > dma-buf release handler already releases the GEM object (which resulted
> > in a refcount underflow) and now also releases the DRM device.
> > 
> > Fixes: 6ad11bc3a0b8 ("staging: drm/omap: dmabuf/prime support")
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> > 
> >  drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c | 17 +++++++++++++----
> >  1 file changed, 13 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
> > b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c index
> > 79dfded9613c..88ad723b3044 100644
> > --- a/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
> > +++ b/drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
> > @@ -75,10 +75,11 @@ static void omap_gem_unmap_dma_buf(struct
> > dma_buf_attachment *attachment,> 
> >  static void omap_gem_dmabuf_release(struct dma_buf *buffer)
> >  {
> >  
> >  	struct drm_gem_object *obj = buffer->priv;
> > 
> > -	/* release reference that was taken when dmabuf was exported
> > -	 * in omap_gem_prime_set()..
> > -	 */
> > +	struct drm_device *dev = obj->dev;
> > +
> > +	/* Release references taken by omap_gem_prime_export(). */
> > 
> >  	drm_gem_object_unreference_unlocked(obj);
> > 
> > +	drm_dev_ref(dev);
> > 
> >  }
> > 
> > @@ -184,13 +185,21 @@ struct dma_buf *omap_gem_prime_export(struct
> > drm_device *dev,> 
> >  		struct drm_gem_object *obj, int flags)
> >  
> >  {
> >  
> >  	DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
> > 
> > +	struct dma_buf *dma_buf;
> > 
> >  	exp_info.ops = &omap_dmabuf_ops;
> >  	exp_info.size = obj->size;
> >  	exp_info.flags = flags;
> >  	exp_info.priv = obj;
> > 
> > -	return dma_buf_export(&exp_info);
> > +	dma_buf = dma_buf_export(&exp_info);
> > +	if (IS_ERR(dma_buf))
> > +		return dma_buf;
> > +
> > +	drm_dev_ref(dev);
> > +	drm_gem_object_reference(obj);
> > +
> > +	return dma_buf;
> > 
> >  }
> 
> Please see drm_gem_dmabuf_export() and drm_gem_dmabuf_release()

Good point, I'll replace the custom implementation by those functions. I had 
noticed drm_gem_dmabuf_release() but for some reason failed to see that 
drm_gem_dmabuf_export() was exported.

> - unless the double drm_dev_ref() wasn't an accident...

Oops :-/ Thank you for catching that.

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-04-21  8:48 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-20 21:33 [PATCH v2 00/10] omapdrm: GEM objects fixes Laurent Pinchart
2017-04-20 21:33 ` [PATCH v2 01/10] drm: omapdrm: Remove remap argument to omap_gem_get_paddr() Laurent Pinchart
2017-04-24 10:09   ` Tomi Valkeinen
2017-04-20 21:33 ` [PATCH v2 02/10] drm: omapdrm: Rename occurrences of paddr to dma_addr Laurent Pinchart
2017-04-24 10:13   ` Tomi Valkeinen
2017-04-20 21:33 ` [PATCH v2 03/10] drm: omapdrm: Rename omap_gem_(get|put)_paddr() to omap_gem_(un)pin() Laurent Pinchart
2017-04-24 10:16   ` Tomi Valkeinen
2017-04-24 14:08     ` Laurent Pinchart
2017-04-20 21:33 ` [PATCH v2 04/10] drm: omapdrm: Lower indentation level in omap_gem_dma_sync_buffer() Laurent Pinchart
2017-04-24 10:22   ` Tomi Valkeinen
2017-04-20 21:33 ` [PATCH v2 05/10] drm: omapdrm: Rename the omap_gem_object addrs field to dma_addrs Laurent Pinchart
2017-04-24 10:24   ` Tomi Valkeinen
2017-04-20 21:33 ` [PATCH v2 06/10] drm: omapdrm: Rename GEM DMA sync functions Laurent Pinchart
2017-04-24 10:32   ` Tomi Valkeinen
2017-04-20 21:33 ` [PATCH v2 07/10] drm: omapdrm: Fix incorrect usage of the term 'cache coherency' Laurent Pinchart
2017-04-24 10:44   ` Tomi Valkeinen
2017-04-24 14:25     ` Laurent Pinchart
2017-04-25  9:07       ` Tomi Valkeinen
2017-04-20 21:33 ` [PATCH v2 08/10] drm: omapdrm: DMA-unmap pages for all buffer types when freeing buffers Laurent Pinchart
2017-04-27 10:48   ` Tomi Valkeinen
2017-04-20 21:33 ` [PATCH v2 09/10] drm: omapdrm: Map pages for DMA in DMA_TO_DEVICE direction Laurent Pinchart
2017-04-27 10:48   ` Tomi Valkeinen
2017-04-20 21:33 ` [PATCH v2 10/10] drm: omapdrm: Take GEM obj and DRM dev references when exporting dmabuf Laurent Pinchart
2017-04-20 23:08   ` Chris Wilson
2017-04-21  8:49     ` Laurent Pinchart [this message]
2017-05-08 18:59       ` [PATCH v2.1 10/10] drm: omapdrm: Take GEM object reference " Laurent Pinchart
2017-05-09  8:14 ` [PATCH v2 00/10] omapdrm: GEM objects fixes Tomi Valkeinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5097550.uOvanFxGd7@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tomi.valkeinen@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.