]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amdgpu/gmc9.0: add bounds checking for cid
authorAlex Deucher <alexander.deucher@amd.com>
Mon, 16 Mar 2026 19:51:08 +0000 (15:51 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 17 Mar 2026 16:19:23 +0000 (12:19 -0400)
The value should never exceed the array size as those
are the only values the hardware is expected to return,
but add checks anyway.

Cc: Benjamin Cheng <benjamin.cheng@amd.com>
Reviewed-by: Benjamin Cheng <benjamin.cheng@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit e14d468304832bcc4a082d95849bc0a41b18ddea)
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c

index e35ed0cc2ec624a7cfeb4950a346f57975a228c6..8eba99aa0f8fa058115e21d1a520a7e214fea446 100644 (file)
@@ -662,28 +662,35 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,
        } else {
                switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
                case IP_VERSION(9, 0, 0):
-                       mmhub_cid = mmhub_client_ids_vega10[cid][rw];
+                       mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_vega10) ?
+                               mmhub_client_ids_vega10[cid][rw] : NULL;
                        break;
                case IP_VERSION(9, 3, 0):
-                       mmhub_cid = mmhub_client_ids_vega12[cid][rw];
+                       mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_vega12) ?
+                               mmhub_client_ids_vega12[cid][rw] : NULL;
                        break;
                case IP_VERSION(9, 4, 0):
-                       mmhub_cid = mmhub_client_ids_vega20[cid][rw];
+                       mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_vega20) ?
+                               mmhub_client_ids_vega20[cid][rw] : NULL;
                        break;
                case IP_VERSION(9, 4, 1):
-                       mmhub_cid = mmhub_client_ids_arcturus[cid][rw];
+                       mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_arcturus) ?
+                               mmhub_client_ids_arcturus[cid][rw] : NULL;
                        break;
                case IP_VERSION(9, 1, 0):
                case IP_VERSION(9, 2, 0):
-                       mmhub_cid = mmhub_client_ids_raven[cid][rw];
+                       mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_raven) ?
+                               mmhub_client_ids_raven[cid][rw] : NULL;
                        break;
                case IP_VERSION(1, 5, 0):
                case IP_VERSION(2, 4, 0):
-                       mmhub_cid = mmhub_client_ids_renoir[cid][rw];
+                       mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_renoir) ?
+                               mmhub_client_ids_renoir[cid][rw] : NULL;
                        break;
                case IP_VERSION(1, 8, 0):
                case IP_VERSION(9, 4, 2):
-                       mmhub_cid = mmhub_client_ids_aldebaran[cid][rw];
+                       mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_aldebaran) ?
+                               mmhub_client_ids_aldebaran[cid][rw] : NULL;
                        break;
                default:
                        mmhub_cid = NULL;