diff mbox

[07/13] drm: Clean up connectors by unreferencing them

Message ID 20161213230814.19598-8-daniel.vetter@ffwll.ch (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Vetter Dec. 13, 2016, 11:08 p.m. UTC
Only static connectors should be left at this point, and we should be
able to clean them out by simply dropping that last reference still
around from drm_connector_init.

If that leaves anything behind then we have a driver bug.

Doing the final cleanup this way also allows us to use
drm_connector_iter, removing the very last place where we walk
connector_list explicitly in drm core&helpers.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 drivers/gpu/drm/drm_mode_config.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Harry Wentland Dec. 15, 2016, 3:45 p.m. UTC | #1
On 2016-12-13 06:08 PM, Daniel Vetter wrote:
> Only static connectors should be left at this point, and we should be
> able to clean them out by simply dropping that last reference still
> around from drm_connector_init.
>
> If that leaves anything behind then we have a driver bug.
>
> Doing the final cleanup this way also allows us to use
> drm_connector_iter, removing the very last place where we walk
> connector_list explicitly in drm core&helpers.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/gpu/drm/drm_mode_config.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c
> index 747a26df0e90..a942536abd60 100644
> --- a/drivers/gpu/drm/drm_mode_config.c
> +++ b/drivers/gpu/drm/drm_mode_config.c
> @@ -397,7 +397,8 @@ EXPORT_SYMBOL(drm_mode_config_init);
>   */
>  void drm_mode_config_cleanup(struct drm_device *dev)
>  {
> -	struct drm_connector *connector, *ot;
> +	struct drm_connector *connector;
> +	struct drm_connector_list_iter conn_iter;
>  	struct drm_crtc *crtc, *ct;
>  	struct drm_encoder *encoder, *enct;
>  	struct drm_framebuffer *fb, *fbt;
> @@ -410,10 +411,16 @@ void drm_mode_config_cleanup(struct drm_device *dev)
>  		encoder->funcs->destroy(encoder);
>  	}
>
> -	list_for_each_entry_safe(connector, ot,
> -				 &dev->mode_config.connector_list, head) {
> -		connector->funcs->destroy(connector);
> +	drm_connector_list_iter_get(dev, &conn_iter);
> +	drm_for_each_connector_iter(connector, &conn_iter) {
> +		/* drm_connector_list_iter holds an full reference to the
> +		 * 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_list_iter_put(&conn_iter);
> +	WARN_ON(!list_empty(&dev->mode_config.connector_list));
>
>  	list_for_each_entry_safe(property, pt, &dev->mode_config.property_list,
>  				 head) {
>

Reviewed-by: Harry Wentland <harry.wentland@amd.com>

Harry
Sean Paul Dec. 16, 2016, 3:03 p.m. UTC | #2
On Tue, Dec 13, 2016 at 6:08 PM, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> Only static connectors should be left at this point, and we should be
> able to clean them out by simply dropping that last reference still
> around from drm_connector_init.
>
> If that leaves anything behind then we have a driver bug.
>
> Doing the final cleanup this way also allows us to use
> drm_connector_iter, removing the very last place where we walk
> connector_list explicitly in drm core&helpers.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/gpu/drm/drm_mode_config.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c
> index 747a26df0e90..a942536abd60 100644
> --- a/drivers/gpu/drm/drm_mode_config.c
> +++ b/drivers/gpu/drm/drm_mode_config.c
> @@ -397,7 +397,8 @@ EXPORT_SYMBOL(drm_mode_config_init);
>   */
>  void drm_mode_config_cleanup(struct drm_device *dev)
>  {
> -       struct drm_connector *connector, *ot;
> +       struct drm_connector *connector;
> +       struct drm_connector_list_iter conn_iter;
>         struct drm_crtc *crtc, *ct;
>         struct drm_encoder *encoder, *enct;
>         struct drm_framebuffer *fb, *fbt;
> @@ -410,10 +411,16 @@ void drm_mode_config_cleanup(struct drm_device *dev)
>                 encoder->funcs->destroy(encoder);
>         }
>
> -       list_for_each_entry_safe(connector, ot,
> -                                &dev->mode_config.connector_list, head) {
> -               connector->funcs->destroy(connector);
> +       drm_connector_list_iter_get(dev, &conn_iter);
> +       drm_for_each_connector_iter(connector, &conn_iter) {
> +               /* drm_connector_list_iter holds an full reference to the
> +                * current connector itself, which means it is inherently safe
> +                * against unreferencing the current connector - but not against
> +                * deleting it right away. */

pedantic nit: doesn't conform to CodingStyle

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

> +               drm_connector_unreference(connector);
>         }
> +       drm_connector_list_iter_put(&conn_iter);
> +       WARN_ON(!list_empty(&dev->mode_config.connector_list));
>
>         list_for_each_entry_safe(property, pt, &dev->mode_config.property_list,
>                                  head) {
> --
> 2.11.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c
index 747a26df0e90..a942536abd60 100644
--- a/drivers/gpu/drm/drm_mode_config.c
+++ b/drivers/gpu/drm/drm_mode_config.c
@@ -397,7 +397,8 @@  EXPORT_SYMBOL(drm_mode_config_init);
  */
 void drm_mode_config_cleanup(struct drm_device *dev)
 {
-	struct drm_connector *connector, *ot;
+	struct drm_connector *connector;
+	struct drm_connector_list_iter conn_iter;
 	struct drm_crtc *crtc, *ct;
 	struct drm_encoder *encoder, *enct;
 	struct drm_framebuffer *fb, *fbt;
@@ -410,10 +411,16 @@  void drm_mode_config_cleanup(struct drm_device *dev)
 		encoder->funcs->destroy(encoder);
 	}
 
-	list_for_each_entry_safe(connector, ot,
-				 &dev->mode_config.connector_list, head) {
-		connector->funcs->destroy(connector);
+	drm_connector_list_iter_get(dev, &conn_iter);
+	drm_for_each_connector_iter(connector, &conn_iter) {
+		/* drm_connector_list_iter holds an full reference to the
+		 * 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_list_iter_put(&conn_iter);
+	WARN_ON(!list_empty(&dev->mode_config.connector_list));
 
 	list_for_each_entry_safe(property, pt, &dev->mode_config.property_list,
 				 head) {