Blob Blame History Raw
From: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
Date: Tue, 11 Jul 2017 18:36:42 -0400
Subject: drm/amd/display: dc_validate_ctx refocunt fixes.
Git-commit: 9a3afbb3ea37b9a6bc16b9d6e4a51b183724158d
Patch-mainline: v4.15-rc1
References: FATE#326289 FATE#326079 FATE#326049 FATE#322398 FATE#326166

In dc_resource_validate_ctx_copy_construct don't override dst
context refcount.

Remove extra retain to new ctx in dc_update_surfaces_and_stream

Signed-off-by: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
Reviewed-by: Tony Cheng <Tony.Cheng@amd.com>
Acked-by: Harry Wentland <Harry.Wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Petr Tesarik <ptesarik@suse.com>
---
 drivers/gpu/drm/amd/display/dc/core/dc.c          |    5 +----
 drivers/gpu/drm/amd/display/dc/core/dc_resource.c |    5 +++++
 2 files changed, 6 insertions(+), 4 deletions(-)

--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -424,6 +424,7 @@ static void allocate_dc_stream_funcs(str
 static void destruct(struct core_dc *dc)
 {
 	dc_release_validate_context(dc->current_context);
+	dc->current_context = NULL;
 
 	destroy_links(dc);
 
@@ -441,9 +442,6 @@ static void destruct(struct core_dc *dc)
 	if (dc->ctx->logger)
 		dal_logger_destroy(&dc->ctx->logger);
 
-	dm_free(dc->current_context);
-	dc->current_context = NULL;
-
 	dm_free(dc->ctx);
 	dc->ctx = NULL;
 }
@@ -1656,7 +1654,6 @@ void dc_update_surfaces_and_stream(struc
 
 	if (core_dc->current_context != context) {
 		dc_release_validate_context(core_dc->current_context);
-		dc_retain_validate_context(context);
 		core_dc->current_context = context;
 	}
 	return;
--- a/drivers/gpu/drm/amd/display/dc/core/dc_resource.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_resource.c
@@ -2166,6 +2166,7 @@ void dc_resource_validate_ctx_copy_const
 		struct validate_context *dst_ctx)
 {
 	int i, j;
+	int ref_count = dst_ctx->ref_count;
 
 	*dst_ctx = *src_ctx;
 
@@ -2186,6 +2187,10 @@ void dc_resource_validate_ctx_copy_const
 			dc_surface_retain(
 				dst_ctx->stream_status[i].surfaces[j]);
 	}
+
+	/* context refcount should not be overridden */
+	dst_ctx->ref_count = ref_count;
+
 }
 
 struct clock_source *dc_resource_find_first_free_pll(