drm/amd/display: Stop amdgpu_dm initialize when link nums greater than max_links
authorHersen Wu <hersenxs.wu@amd.com>
Wed, 24 Apr 2024 20:15:15 +0000 (16:15 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 2 May 2024 20:18:16 +0000 (16:18 -0400)
[Why]
Coverity report OVERRUN warning. There are
only max_links elements within dc->links. link
count could up to AMDGPU_DM_MAX_DISPLAY_INDEX 31.

[How]
Make sure link count less than max_links.

Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Acked-by: Tom Chung <chiahsuan.chung@amd.com>
Signed-off-by: Hersen Wu <hersenxs.wu@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

index cce959302315b73689190e23911b443bcfd545c8..35bf77fe53af051079cf70153a17287a6e7110de 100644 (file)
@@ -4689,17 +4689,17 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev)
                }
        }
 
+       if (link_cnt > MAX_LINKS) {
+               DRM_ERROR(
+                       "KMS: Cannot support more than %d display indexes\n",
+                               MAX_LINKS);
+               goto fail;
+       }
+
        /* loops over all connectors on the board */
        for (i = 0; i < link_cnt; i++) {
                struct dc_link *link = NULL;
 
-               if (i > AMDGPU_DM_MAX_DISPLAY_INDEX) {
-                       DRM_ERROR(
-                               "KMS: Cannot support more than %d display indexes\n",
-                                       AMDGPU_DM_MAX_DISPLAY_INDEX);
-                       continue;
-               }
-
                link = dc_get_link_at_index(dm->dc, i);
 
                if (link->connector_signal == SIGNAL_TYPE_VIRTUAL) {