drm/amd/display: Add NULL-checks in dml2 assigned pipe search
authorAllen Pan <allen.pan@amd.com>
Tue, 9 Jan 2024 19:54:02 +0000 (14:54 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 22 Jan 2024 22:13:27 +0000 (17:13 -0500)
[Why]
NULL-deref regression after:
"drm/amd/display: Fix dml2 assigned pipe search"

[How]
Add verification for potential NULLs

Fixes: d451b534e0b4 ("drm/amd/display: Fix dml2 assigned pipe search")
Reviewed-by: Charlene Liu <charlene.liu@amd.com>
Reviewed-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Acked-by: Roman Li <roman.li@amd.com>
Signed-off-by: Gabe Teeger <gabe.teeger@amd.com>
Signed-off-by: Allen Pan <allen.pan@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/dml2/dml2_dc_resource_mgmt.c

index a0ce681..a52c594 100644 (file)
@@ -146,19 +146,24 @@ static unsigned int find_pipes_assigned_to_plane(struct dml2_context *ctx,
        for (i = 0; i < ctx->config.dcn_pipe_count; i++) {
                struct pipe_ctx *pipe = &state->res_ctx.pipe_ctx[i];
 
-               if (!pipe->stream)
+               if (!pipe->plane_state || !pipe->stream)
                        continue;
 
                get_plane_id(ctx, state, pipe->plane_state, pipe->stream->stream_id,
                                        ctx->v20.scratch.dml_to_dc_pipe_mapping.dml_pipe_idx_to_plane_index[pipe->pipe_idx],
                                        &plane_id_assigned_to_pipe);
-               if (pipe->plane_state && plane_id_assigned_to_pipe == plane_id && !pipe->top_pipe && !pipe->prev_odm_pipe) {
+               if (plane_id_assigned_to_pipe == plane_id && !pipe->prev_odm_pipe
+                               && (!pipe->top_pipe || pipe->top_pipe->plane_state != pipe->plane_state)) {
                        while (pipe) {
-                               struct pipe_ctx *mpo_pipe = pipe;
-
-                               while (mpo_pipe) {
-                                       pipes[num_found++] = mpo_pipe->pipe_idx;
-                                       mpo_pipe = mpo_pipe->bottom_pipe;
+                               struct pipe_ctx *mpc_pipe = pipe;
+
+                               while (mpc_pipe) {
+                                       pipes[num_found++] = mpc_pipe->pipe_idx;
+                                       mpc_pipe = mpc_pipe->bottom_pipe;
+                                       if (!mpc_pipe)
+                                               break;
+                                       if (mpc_pipe->plane_state != pipe->plane_state)
+                                               mpc_pipe = NULL;
                                }
                                pipe = pipe->next_odm_pipe;
                        }