drm/amd/display: Do not return negative stream id for array
authorAlex Hung <alex.hung@amd.com>
Mon, 22 Apr 2024 19:43:14 +0000 (13:43 -0600)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 26 Apr 2024 21:22:44 +0000 (17:22 -0400)
[WHY]
resource_stream_to_stream_idx returns an array index and it return -1
when not found; however, -1 is not a valid array index number.

[HOW]
When this happens, call ASSERT(), and return a zero instead.

This fixes an OVERRUN and an NEGATIVE_RETURNS issues reported by Coverity.

Reviewed-by: Rodrigo Siqueira <rodrigo.siqueira@amd.com>
Acked-by: Wayne Lin <wayne.lin@amd.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/core/dc_resource.c

index 25b5e41648c422828a612986861ad2b3aa6c6788..f281dc89550bc72c11aeedd57668ca5090534080 100644 (file)
@@ -2243,6 +2243,13 @@ static int resource_stream_to_stream_idx(struct dc_state *state,
                        stream_idx = i;
                        break;
                }
+
+       /* never return negative array index */
+       if (stream_idx == -1) {
+               ASSERT(0);
+               return 0;
+       }
+
        return stream_idx;
 }