drm/amd/display: retain/release at proper places in link_enc assignment
authorSung Joon Kim <sungkim@amd.com>
Mon, 8 Nov 2021 21:35:18 +0000 (16:35 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 24 Nov 2021 19:06:52 +0000 (14:06 -0500)
[why]
Need to keep track of number of
references to stream pointer.

[how]
Call stream retain/release whenever
necessary in link_enc table assignment
sequence.

Reviewed-by: Aric Cyr <Aric.Cyr@amd.com>
Acked-by: Qingqing Zhuo <qingqing.zhuo@amd.com>
Signed-off-by: Sung Joon Kim <sungkim@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/core/dc.c
drivers/gpu/drm/amd/display/dc/core/dc_link_enc_cfg.c

index 0545e17f1d6016ac24bc7e593025d149fff4a304..17b7408d84b70e1ac39c70675fa154be05cd9c0a 100644 (file)
@@ -808,6 +808,10 @@ void dc_stream_set_static_screen_params(struct dc *dc,
 
 static void dc_destruct(struct dc *dc)
 {
+       // reset link encoder assignment table on destruct
+       if (dc->res_pool->funcs->link_encs_assign)
+               link_enc_cfg_init(dc, dc->current_state);
+
        if (dc->current_state) {
                dc_release_state(dc->current_state);
                dc->current_state = NULL;
index 8b319992c71db20e05d3b3cbf74a71f8fdc9284e..a55944da8d53fbb18da1d9e237c21b9234163e09 100644 (file)
@@ -151,6 +151,7 @@ static void add_link_enc_assignment(
                                                .ep_type = stream->link->ep_type},
                                        .eng_id = eng_id,
                                        .stream = stream};
+                               dc_stream_retain(stream);
                                state->res_ctx.link_enc_cfg_ctx.link_enc_avail[eng_idx] = ENGINE_ID_UNKNOWN;
                                stream->link_enc = stream->ctx->dc->res_pool->link_encoders[eng_idx];
                                break;
@@ -247,7 +248,10 @@ static void clear_enc_assignments(const struct dc *dc, struct dc_state *state)
        for (i = 0; i < MAX_PIPES; i++) {
                state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].valid = false;
                state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].eng_id = ENGINE_ID_UNKNOWN;
-               state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].stream = NULL;
+               if (state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].stream != NULL) {
+                       dc_stream_release(state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].stream);
+                       state->res_ctx.link_enc_cfg_ctx.link_enc_assignments[i].stream = NULL;
+               }
        }
 
        for (i = 0; i < dc->res_pool->res_cap->num_dig_link_enc; i++) {