[PATCH 3/6] drm: Introduce drm_connector_{get,put}()

Sean Paul seanpaul at chromium.org
Wed Feb 8 19:33:46 UTC 2017


On Wed, Feb 08, 2017 at 07:24:05PM +0100, Thierry Reding wrote:
> From: Thierry Reding <treding at nvidia.com>
> 
> For consistency with other reference counting APIs in the kernel, add
> drm_connector_get() and drm_connector_put() functions to reference count
> connectors.
> 
> Compatibility aliases are added to keep existing code working. To help
> speed up the transition, all the instances of the old functions in the
> DRM core are already replaced in this commit.
> 
> The existing semantic patch for mode object reference count conversion
> is extended for these new helpers.
> 

drivers/gpu/drm/*

Reviewed-by: Sean Paul <seanpaul at chromium.org>

> Signed-off-by: Thierry Reding <treding at nvidia.com>
> ---
>  drivers/gpu/drm/drm_atomic.c             |  8 +++----
>  drivers/gpu/drm/drm_atomic_helper.c      |  4 ++--
>  drivers/gpu/drm/drm_connector.c          | 10 ++++----
>  drivers/gpu/drm/drm_crtc.c               |  2 +-
>  drivers/gpu/drm/drm_crtc_helper.c        |  6 ++---
>  drivers/gpu/drm/drm_fb_helper.c          | 12 +++++-----
>  drivers/gpu/drm/drm_mode_config.c        |  2 +-
>  include/drm/drm_connector.h              | 41 +++++++++++++++++++++++++-------
>  scripts/coccinelle/api/drm-get-put.cocci | 10 ++++++++
>  9 files changed, 65 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index 2bb0a759e8ec..82bad40b2f3e 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -150,7 +150,7 @@ void drm_atomic_state_default_clear(struct drm_atomic_state *state)
>  						       state->connectors[i].state);
>  		state->connectors[i].ptr = NULL;
>  		state->connectors[i].state = NULL;
> -		drm_connector_unreference(connector);
> +		drm_connector_put(connector);
>  	}
>  
>  	for (i = 0; i < config->num_crtc; i++) {
> @@ -1026,7 +1026,7 @@ drm_atomic_get_connector_state(struct drm_atomic_state *state,
>  	if (!connector_state)
>  		return ERR_PTR(-ENOMEM);
>  
> -	drm_connector_reference(connector);
> +	drm_connector_get(connector);
>  	state->connectors[index].state = connector_state;
>  	state->connectors[index].ptr = connector;
>  	connector_state->state = state;
> @@ -1357,7 +1357,7 @@ drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
>  		crtc_state->connector_mask &=
>  			~(1 << drm_connector_index(conn_state->connector));
>  
> -		drm_connector_unreference(conn_state->connector);
> +		drm_connector_put(conn_state->connector);
>  		conn_state->crtc = NULL;
>  	}
>  
> @@ -1369,7 +1369,7 @@ drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
>  		crtc_state->connector_mask |=
>  			1 << drm_connector_index(conn_state->connector);
>  
> -		drm_connector_reference(conn_state->connector);
> +		drm_connector_get(conn_state->connector);
>  		conn_state->crtc = crtc;
>  
>  		DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d:%s]\n",
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
> index 9a08445a7a7a..9f2c28ddf948 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -3272,7 +3272,7 @@ __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
>  {
>  	memcpy(state, connector->state, sizeof(*state));
>  	if (state->crtc)
> -		drm_connector_reference(connector);
> +		drm_connector_get(connector);
>  }
>  EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);
>  
> @@ -3398,7 +3398,7 @@ void
>  __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)
>  {
>  	if (state->crtc)
> -		drm_connector_unreference(state->connector);
> +		drm_connector_put(state->connector);
>  }
>  EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);
>  
> diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> index 0616062b055a..0dc0e5b33f8a 100644
> --- a/drivers/gpu/drm/drm_connector.c
> +++ b/drivers/gpu/drm/drm_connector.c
> @@ -35,8 +35,8 @@
>   * als fixed panels or anything else that can display pixels in some form. As
>   * opposed to all other KMS objects representing hardware (like CRTC, encoder or
>   * plane abstractions) connectors can be hotplugged and unplugged at runtime.
> - * Hence they are reference-counted using drm_connector_reference() and
> - * drm_connector_unreference().
> + * Hence they are reference-counted using drm_connector_get() and
> + * drm_connector_put().
>   *
>   * KMS driver must create, initialize, register and attach at a &struct
>   * drm_connector for each such sink. The instance is created as other KMS
> @@ -545,7 +545,7 @@ drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
>  	spin_unlock_irqrestore(&config->connector_list_lock, flags);
>  
>  	if (old_conn)
> -		drm_connector_unreference(old_conn);
> +		drm_connector_put(old_conn);
>  
>  	return iter->conn;
>  }
> @@ -564,7 +564,7 @@ void drm_connector_list_iter_put(struct drm_connector_list_iter *iter)
>  {
>  	iter->dev = NULL;
>  	if (iter->conn)
> -		drm_connector_unreference(iter->conn);
> +		drm_connector_put(iter->conn);
>  	lock_release(&connector_list_iter_dep_map, 0, _RET_IP_);
>  }
>  EXPORT_SYMBOL(drm_connector_list_iter_put);
> @@ -1249,7 +1249,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
>  out:
>  	mutex_unlock(&dev->mode_config.mutex);
>  out_unref:
> -	drm_connector_unreference(connector);
> +	drm_connector_put(connector);
>  
>  	return ret;
>  }
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index e2284539f82c..9594c623799b 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -685,7 +685,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
>  	if (connector_set) {
>  		for (i = 0; i < crtc_req->count_connectors; i++) {
>  			if (connector_set[i])
> -				drm_connector_unreference(connector_set[i]);
> +				drm_connector_put(connector_set[i]);
>  		}
>  	}
>  	kfree(connector_set);
> diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
> index 44ba0e990d6c..536051c627d8 100644
> --- a/drivers/gpu/drm/drm_crtc_helper.c
> +++ b/drivers/gpu/drm/drm_crtc_helper.c
> @@ -465,7 +465,7 @@ drm_crtc_helper_disable(struct drm_crtc *crtc)
>  			connector->dpms = DRM_MODE_DPMS_OFF;
>  
>  			/* we keep a reference while the encoder is bound */
> -			drm_connector_unreference(connector);
> +			drm_connector_put(connector);
>  		}
>  		drm_connector_list_iter_put(&conn_iter);
>  	}
> @@ -623,7 +623,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
>  	for (ro = 0; ro < set->num_connectors; ro++) {
>  		if (set->connectors[ro]->encoder)
>  			continue;
> -		drm_connector_reference(set->connectors[ro]);
> +		drm_connector_get(set->connectors[ro]);
>  	}
>  
>  	/* a) traverse passed in connector list and get encoders for them */
> @@ -772,7 +772,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
>  	for (ro = 0; ro < set->num_connectors; ro++) {
>  		if (set->connectors[ro]->encoder)
>  			continue;
> -		drm_connector_unreference(set->connectors[ro]);
> +		drm_connector_put(set->connectors[ro]);
>  	}
>  
>  	/* Try to restore the config */
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index f6d4d9700734..ee1361a24b3a 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -141,7 +141,7 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
>  		struct drm_fb_helper_connector *fb_helper_connector =
>  			fb_helper->connector_info[i];
>  
> -		drm_connector_unreference(fb_helper_connector->connector);
> +		drm_connector_put(fb_helper_connector->connector);
>  
>  		kfree(fb_helper_connector);
>  		fb_helper->connector_info[i] = NULL;
> @@ -178,7 +178,7 @@ int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_
>  	if (!fb_helper_connector)
>  		return -ENOMEM;
>  
> -	drm_connector_reference(connector);
> +	drm_connector_get(connector);
>  	fb_helper_connector->connector = connector;
>  	fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
>  	return 0;
> @@ -204,7 +204,7 @@ int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
>  	if (i == fb_helper->connector_count)
>  		return -EINVAL;
>  	fb_helper_connector = fb_helper->connector_info[i];
> -	drm_connector_unreference(fb_helper_connector->connector);
> +	drm_connector_put(fb_helper_connector->connector);
>  
>  	for (j = i + 1; j < fb_helper->connector_count; j++) {
>  		fb_helper->connector_info[j - 1] = fb_helper->connector_info[j];
> @@ -626,7 +626,7 @@ static void drm_fb_helper_modeset_release(struct drm_fb_helper *helper,
>  	int i;
>  
>  	for (i = 0; i < modeset->num_connectors; i++) {
> -		drm_connector_unreference(modeset->connectors[i]);
> +		drm_connector_put(modeset->connectors[i]);
>  		modeset->connectors[i] = NULL;
>  	}
>  	modeset->num_connectors = 0;
> @@ -643,7 +643,7 @@ static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
>  	int i;
>  
>  	for (i = 0; i < helper->connector_count; i++) {
> -		drm_connector_unreference(helper->connector_info[i]->connector);
> +		drm_connector_put(helper->connector_info[i]->connector);
>  		kfree(helper->connector_info[i]);
>  	}
>  	kfree(helper->connector_info);
> @@ -2184,7 +2184,7 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper,
>  			fb_crtc->y = offset->y;
>  			modeset->mode = drm_mode_duplicate(dev,
>  							   fb_crtc->desired_mode);
> -			drm_connector_reference(connector);
> +			drm_connector_get(connector);
>  			modeset->connectors[modeset->num_connectors++] = connector;
>  			modeset->fb = fb_helper->fb;
>  			modeset->x = offset->x;
> diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c
> index 884cc4d26fb5..20aec165abd7 100644
> --- a/drivers/gpu/drm/drm_mode_config.c
> +++ b/drivers/gpu/drm/drm_mode_config.c
> @@ -418,7 +418,7 @@ void drm_mode_config_cleanup(struct drm_device *dev)
>  		 * current connector itself, which means it is inherently safe
>  		 * against unreferencing the current connector - but not against
>  		 * deleting it right away. */
> -		drm_connector_unreference(connector);
> +		drm_connector_put(connector);
>  	}
>  	drm_connector_list_iter_put(&conn_iter);
>  	if (WARN_ON(!list_empty(&dev->mode_config.connector_list))) {
> diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
> index e5e1eddd19fb..d649bec96937 100644
> --- a/include/drm/drm_connector.h
> +++ b/include/drm/drm_connector.h
> @@ -795,25 +795,50 @@ static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
>  }
>  
>  /**
> - * drm_connector_reference - incr the connector refcnt
> - * @connector: connector
> + * drm_connector_get - acquire a connector reference
> + * @connector: DRM connector
>   *
>   * This function increments the connector's refcount.
>   */
> +static inline void drm_connector_get(struct drm_connector *connector)
> +{
> +	drm_mode_object_get(&connector->base);
> +}
> +
> +/**
> + * drm_connector_put - release a connector reference
> + * @connector: DRM connector
> + *
> + * This function decrements the connector's reference count and frees the
> + * object if the reference count drops to zero.
> + */
> +static inline void drm_connector_put(struct drm_connector *connector)
> +{
> +	drm_mode_object_put(&connector->base);
> +}
> +
> +/**
> + * drm_connector_reference - acquire a connector reference
> + * @connector: DRM connector
> + *
> + * This is a compatibility alias for drm_connector_get() and should not be
> + * used by new code.
> + */
>  static inline void drm_connector_reference(struct drm_connector *connector)
>  {
> -	drm_mode_object_reference(&connector->base);
> +	drm_connector_get(connector);
>  }
>  
>  /**
> - * drm_connector_unreference - unref a connector
> - * @connector: connector to unref
> + * drm_connector_unreference - release a connector reference
> + * @connector: DRM connector
>   *
> - * This function decrements the connector's refcount and frees it if it drops to zero.
> + * This is a compatibility alias for drm_connector_put() and should not be
> + * used by new code.
>   */
>  static inline void drm_connector_unreference(struct drm_connector *connector)
>  {
> -	drm_mode_object_unreference(&connector->base);
> +	drm_connector_put(connector);
>  }
>  
>  const char *drm_get_connector_status_name(enum drm_connector_status status);
> @@ -905,7 +930,7 @@ void drm_connector_list_iter_put(struct drm_connector_list_iter *iter);
>   *
>   * Note that @connector is only valid within the list body, if you want to use
>   * @connector after calling drm_connector_list_iter_put() then you need to grab
> - * your own reference first using drm_connector_reference().
> + * your own reference first using drm_connector_get().
>   */
>  #define drm_for_each_connector_iter(connector, iter) \
>  	while ((connector = drm_connector_list_iter_next(iter)))
> diff --git a/scripts/coccinelle/api/drm-get-put.cocci b/scripts/coccinelle/api/drm-get-put.cocci
> index a3742447c981..8a4c2cb7889e 100644
> --- a/scripts/coccinelle/api/drm-get-put.cocci
> +++ b/scripts/coccinelle/api/drm-get-put.cocci
> @@ -20,6 +20,12 @@ expression object;
>  |
>  - drm_mode_object_unreference(object)
>  + drm_mode_object_put(object)
> +|
> +- drm_connector_reference(object)
> ++ drm_connector_get(object)
> +|
> +- drm_connector_unreference(object)
> ++ drm_connector_put(object)
>  )
>  
>  @r depends on report@
> @@ -31,6 +37,10 @@ position p;
>  drm_mode_object_unreference at p(object)
>  |
>  drm_mode_object_reference at p(object)
> +|
> +drm_connector_unreference at p(object)
> +|
> +drm_connector_reference at p(object)
>  )
>  
>  @script:python depends on report@
> -- 
> 2.11.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Sean Paul, Software Engineer, Google / Chromium OS


More information about the dri-devel mailing list