drm/amdgpu: add bounds check to prevent array overflow

Add bounds check to prevent array overflow.

v2:
  Add warning messages.

Signed-off-by: YiPeng Chai <YiPeng.Chai@amd.com>
Reviewed-by: Tao Zhou <tao.zhou1@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
YiPeng Chai 2026-06-16 16:18:22 +08:00 committed by Alex Deucher
parent a63e82d499
commit db15c49a17

View File

@ -5064,6 +5064,13 @@ static void amdgpu_register_bad_pages_mca_notifier(struct amdgpu_device *adev)
* Use this list instead of mgpu_info to find the amdgpu
* device on which the UMC error was reported.
*/
if (mce_adev_list.num_gpu >= MAX_GPU_INSTANCE) {
dev_warn_ratelimited(adev->dev,
"mce_adev_list full, skip notifier registration (max=%d)\n",
MAX_GPU_INSTANCE);
return;
}
mce_adev_list.devs[mce_adev_list.num_gpu++] = adev;
/*