[PATCH 01/15] drm/mode: rework drm_mode_object_put to drm_mode_object_unregister.

Daniel Vetter daniel at ffwll.ch
Thu Apr 21 08:03:31 UTC 2016


On Fri, Apr 15, 2016 at 03:10:32PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
> 
> This changes the code to handle being called multiple times without
> side effects. The new names seems more suitable for what it does.
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>

Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>

> ---
>  drivers/gpu/drm/drm_crtc.c          | 37 +++++++++++++++++++++----------------
>  drivers/gpu/drm/drm_crtc_internal.h |  4 ++--
>  drivers/gpu/drm/drm_modes.c         |  2 +-
>  3 files changed, 24 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index e08f962..21cb8dc 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -323,19 +323,24 @@ static void drm_mode_object_register(struct drm_device *dev,
>  }
>  
>  /**
> - * drm_mode_object_put - free a modeset identifer
> + * drm_mode_object_unregister - free a modeset identifer
>   * @dev: DRM device
>   * @object: object to free
>   *
> - * Free @id from @dev's unique identifier pool. Note that despite the _get
> - * postfix modeset identifiers are _not_ reference counted. Hence don't use this
> + * Free @id from @dev's unique identifier pool.
> + * This function can be called multiple times, and guards against
> + * multiple removals.
> + * These modeset identifiers are _not_ reference counted. Hence don't use this
>   * for reference counted modeset objects like framebuffers.
>   */
> -void drm_mode_object_put(struct drm_device *dev,
> +void drm_mode_object_unregister(struct drm_device *dev,
>  			 struct drm_mode_object *object)
>  {
>  	mutex_lock(&dev->mode_config.idr_mutex);
> -	idr_remove(&dev->mode_config.crtc_idr, object->id);
> +	if (object->id) {
> +		idr_remove(&dev->mode_config.crtc_idr, object->id);
> +		object->id = 0;
> +	}
>  	mutex_unlock(&dev->mode_config.idr_mutex);
>  }
>  
> @@ -705,7 +710,7 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
>  				       drm_num_crtcs(dev));
>  	}
>  	if (!crtc->name) {
> -		drm_mode_object_put(dev, &crtc->base);
> +		drm_mode_object_unregister(dev, &crtc->base);
>  		return -ENOMEM;
>  	}
>  
> @@ -747,7 +752,7 @@ void drm_crtc_cleanup(struct drm_crtc *crtc)
>  
>  	drm_modeset_lock_fini(&crtc->mutex);
>  
> -	drm_mode_object_put(dev, &crtc->base);
> +	drm_mode_object_unregister(dev, &crtc->base);
>  	list_del(&crtc->head);
>  	dev->mode_config.num_crtc--;
>  
> @@ -972,7 +977,7 @@ out_put_id:
>  		ida_remove(&config->connector_ida, connector->connector_id);
>  out_put:
>  	if (ret)
> -		drm_mode_object_put(dev, &connector->base);
> +		drm_mode_object_unregister(dev, &connector->base);
>  
>  out_unlock:
>  	drm_modeset_unlock_all(dev);
> @@ -1010,7 +1015,7 @@ void drm_connector_cleanup(struct drm_connector *connector)
>  		   connector->connector_id);
>  
>  	kfree(connector->display_info.bus_formats);
> -	drm_mode_object_put(dev, &connector->base);
> +	drm_mode_object_unregister(dev, &connector->base);
>  	kfree(connector->name);
>  	connector->name = NULL;
>  	list_del(&connector->head);
> @@ -1138,7 +1143,7 @@ int drm_encoder_init(struct drm_device *dev,
>  
>  out_put:
>  	if (ret)
> -		drm_mode_object_put(dev, &encoder->base);
> +		drm_mode_object_unregister(dev, &encoder->base);
>  
>  out_unlock:
>  	drm_modeset_unlock_all(dev);
> @@ -1181,7 +1186,7 @@ void drm_encoder_cleanup(struct drm_encoder *encoder)
>  	struct drm_device *dev = encoder->dev;
>  
>  	drm_modeset_lock_all(dev);
> -	drm_mode_object_put(dev, &encoder->base);
> +	drm_mode_object_unregister(dev, &encoder->base);
>  	kfree(encoder->name);
>  	list_del(&encoder->head);
>  	dev->mode_config.num_encoder--;
> @@ -1242,7 +1247,7 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
>  					    GFP_KERNEL);
>  	if (!plane->format_types) {
>  		DRM_DEBUG_KMS("out of memory when allocating plane\n");
> -		drm_mode_object_put(dev, &plane->base);
> +		drm_mode_object_unregister(dev, &plane->base);
>  		return -ENOMEM;
>  	}
>  
> @@ -1258,7 +1263,7 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
>  	}
>  	if (!plane->name) {
>  		kfree(plane->format_types);
> -		drm_mode_object_put(dev, &plane->base);
> +		drm_mode_object_unregister(dev, &plane->base);
>  		return -ENOMEM;
>  	}
>  
> @@ -1338,7 +1343,7 @@ void drm_plane_cleanup(struct drm_plane *plane)
>  
>  	drm_modeset_lock_all(dev);
>  	kfree(plane->format_types);
> -	drm_mode_object_put(dev, &plane->base);
> +	drm_mode_object_unregister(dev, &plane->base);
>  
>  	BUG_ON(list_empty(&plane->head));
>  
> @@ -4029,7 +4034,7 @@ void drm_property_destroy(struct drm_device *dev, struct drm_property *property)
>  
>  	if (property->num_values)
>  		kfree(property->values);
> -	drm_mode_object_put(dev, &property->base);
> +	drm_mode_object_unregister(dev, &property->base);
>  	list_del(&property->head);
>  	kfree(property);
>  }
> @@ -4307,7 +4312,7 @@ static void drm_property_free_blob(struct kref *kref)
>  
>  	list_del(&blob->head_global);
>  	list_del(&blob->head_file);
> -	drm_mode_object_put(blob->dev, &blob->base);
> +	drm_mode_object_unregister(blob->dev, &blob->base);
>  
>  	kfree(blob);
>  }
> diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
> index 247dc8b..a78c138 100644
> --- a/drivers/gpu/drm/drm_crtc_internal.h
> +++ b/drivers/gpu/drm/drm_crtc_internal.h
> @@ -33,8 +33,8 @@
>  
>  int drm_mode_object_get(struct drm_device *dev,
>  			struct drm_mode_object *obj, uint32_t obj_type);
> -void drm_mode_object_put(struct drm_device *dev,
> -			 struct drm_mode_object *object);
> +void drm_mode_object_unregister(struct drm_device *dev,
> +				struct drm_mode_object *object);
>  
>  /* drm_atomic.c */
>  int drm_atomic_get_property(struct drm_mode_object *obj,
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index f7448a5..7def3d5 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -98,7 +98,7 @@ void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
>  	if (!mode)
>  		return;
>  
> -	drm_mode_object_put(dev, &mode->base);
> +	drm_mode_object_unregister(dev, &mode->base);
>  
>  	kfree(mode);
>  }
> -- 
> 2.5.5
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list