dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
	Daniel Stone <daniels@collabora.com>,
	dri-devel@lists.freedesktop.org, Dave Airlie <airlied@redhat.com>
Subject: Re: [PATCH] drm: Avoid connector reference imbalance on error path
Date: Wed, 18 May 2016 12:24:42 +0200	[thread overview]
Message-ID: <20160518102442.GD27098@phenom.ffwll.local> (raw)
In-Reply-To: <1462535265-13058-1-git-send-email-chris@chris-wilson.co.uk>

On Fri, May 06, 2016 at 12:47:45PM +0100, Chris Wilson wrote:
> Whilst looking at the fallout from using connector references for
> atomic, I noticed that there is an early return buried in
> drm_atomic_set_crtc_for_connector() that if hit could cause us to leak a
> reference on the connector.
> 
> Fixes: d2307dea14 (drm/atomic: use connector references (v3))
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Daniel Stone <daniels@collabora.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Dave Airlie <airlied@redhat.com>

Applied to drm-misc, thanks.
-Daniel

> ---
>  drivers/gpu/drm/drm_atomic.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 86e89db02ed7..3ff1ed7b33db 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1160,14 +1160,18 @@ drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
>  {
>  	struct drm_crtc_state *crtc_state;
>  
> -	if (crtc)
> -		drm_connector_reference(conn_state->connector);
> -	if (conn_state->crtc && conn_state->crtc != crtc) {
> +	if (conn_state->crtc == crtc)
> +		return 0;
> +
> +	if (conn_state->crtc) {
>  		crtc_state = drm_atomic_get_existing_crtc_state(conn_state->state,
>  								conn_state->crtc);
>  
>  		crtc_state->connector_mask &=
>  			~(1 << drm_connector_index(conn_state->connector));
> +
> +		drm_connector_unreference(conn_state->connector);
> +		conn_state->crtc = NULL;
>  	}
>  
>  	if (crtc) {
> @@ -1177,18 +1181,16 @@ drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
>  
>  		crtc_state->connector_mask |=
>  			1 << drm_connector_index(conn_state->connector);
> -	}
>  
> -	if (conn_state->crtc)
> -		drm_connector_unreference(conn_state->connector);
> -	conn_state->crtc = crtc;
> +		drm_connector_reference(conn_state->connector);
> +		conn_state->crtc = crtc;
>  
> -	if (crtc)
>  		DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d:%s]\n",
>  				 conn_state, crtc->base.id, crtc->name);
> -	else
> +	} else {
>  		DRM_DEBUG_ATOMIC("Link connector state %p to [NOCRTC]\n",
>  				 conn_state);
> +	}
>  
>  	return 0;
>  }
> -- 
> 2.8.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

      reply	other threads:[~2016-05-18 10:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06 11:47 [PATCH] drm: Avoid connector reference imbalance on error path Chris Wilson
2016-05-18 10:24 ` Daniel Vetter [this message]

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=20160518102442.GD27098@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=airlied@redhat.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniels@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox