All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jyri Sarha <jsarha@ti.com>
Cc: tomi.valkeinen@ti.com, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/drm_bridge: adjust bridge module's refcount
Date: Wed, 30 Nov 2016 10:37:46 +0200	[thread overview]
Message-ID: <8610214.hSyeADxPWm@avalon> (raw)
In-Reply-To: <bcd2f5de-8697-09eb-ce25-ac5b1c4bcdef@ti.com>

Hi Jyri,

On Wednesday 30 Nov 2016 10:32:40 Jyri Sarha wrote:
> On 11/30/16 00:06, Laurent Pinchart wrote:
> >> >  /**
> >> >   * drm_bridge_remove - remove the given bridge from the global bridge
> >> >   list
> >> > @@ -114,6 +118,9 @@ int drm_bridge_attach(struct drm_device *dev,
> >> > struct drm_bridge *bridge)
> >> >  	if (bridge->dev)
> >> >  		return -EBUSY;
> >> > 
> >> > +	if (!try_module_get(bridge->module))
> >> > +		return -ENOENT;
> > 
> > Isn't this still racy ? What happens if the module is removed right before
> > this call ? Won't the bridge object be freed, and this code then try to
> > call try_module_get() on freed memory ?
> > 
> > To fix this properly I think we need to make the bridge object refcounted,
> > with a release callback to signal to the bridge driver that memory can be
> > freed. The refcount should be increased in of_drm_find_bridge(), and
> > decreased in a new drm_bridge_put() function (the "fun" part will be to
> > update drivers to call that :-S).
> 
> I think another option would be to find and attach the bridge object
> atomically by holding the bridge_lock until the try_module_get() has
> succeeded.
> 
> AFAIU, if the module unload is triggered while holding the bridge_lock
> but before the try_module_get() call, then try_module_get() would return
> false and the attach call will return failure.

This would require combining lookup and attach in all cases. I'm not sure that 
would be very convenient for drivers. Keeping the two operations separate 
would be more flexible.

> > The module refcount still needs to be increased in drm_bridge_attach()
> > like you do here, but you'll need to protect it with bridge_lock to avoid
> > a race between try_module_get() and drm_bridge_remove().

-- 
Regards,

Laurent Pinchart

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

  reply	other threads:[~2016-11-30  8:37 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161129211315epcas3p2a805abe8449509312f481ab7dcea96ef@epcas3p2.samsung.com>
2016-11-29 21:12 ` [PATCH] drm/drm_bridge: adjust bridge module's refcount Jyri Sarha
2016-11-29 21:30   ` Jyri Sarha
2016-11-29 22:06   ` Laurent Pinchart
2016-11-30  8:13     ` Daniel Vetter
2016-11-30  8:25       ` Laurent Pinchart
2016-11-30  9:12         ` Daniel Vetter
2016-11-30  9:56           ` Laurent Pinchart
2016-11-30 10:55             ` Daniel Vetter
2016-11-30 11:03               ` Laurent Pinchart
2016-11-30 13:09                 ` Daniel Vetter
2016-12-01  7:07                   ` Andrzej Hajda
2016-12-01  7:18                     ` Daniel Vetter
2016-12-01 13:22                       ` Andrzej Hajda
2016-12-01 15:12                         ` Daniel Vetter
2016-12-02  6:49                           ` Andrzej Hajda
2016-11-30  8:32     ` Jyri Sarha
2016-11-30  8:37       ` Laurent Pinchart [this message]
2016-11-30  8:55         ` Jyri Sarha
2016-11-30  9:03           ` Laurent Pinchart
2016-11-30  9:13             ` Jyri Sarha
2016-11-30  9:30               ` Laurent Pinchart
2016-11-30  8:11   ` Andrzej Hajda
2016-11-30  8:16     ` Laurent Pinchart
2016-11-30  9:26       ` Andrzej Hajda
2016-11-30  9:39         ` Laurent Pinchart
2016-12-01  6:50           ` Andrzej Hajda

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=8610214.hSyeADxPWm@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jsarha@ti.com \
    --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.