]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amdgpu/mmhub2.0: add bounds checking for cid
authorAlex Deucher <alexander.deucher@amd.com>
Wed, 4 Mar 2026 22:22:43 +0000 (17:22 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 17 Mar 2026 16:18:34 +0000 (12:18 -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.

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

index a0cc8e218ca1ea2c10349e48205d82f3ef490b06..534cb4c544dc45db4b8a539496e938d70ad0cc8c 100644 (file)
@@ -154,14 +154,17 @@ mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev,
        switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
        case IP_VERSION(2, 0, 0):
        case IP_VERSION(2, 0, 2):
-               mmhub_cid = mmhub_client_ids_navi1x[cid][rw];
+               mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_navi1x) ?
+                       mmhub_client_ids_navi1x[cid][rw] : NULL;
                break;
        case IP_VERSION(2, 1, 0):
        case IP_VERSION(2, 1, 1):
-               mmhub_cid = mmhub_client_ids_sienna_cichlid[cid][rw];
+               mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_sienna_cichlid) ?
+                       mmhub_client_ids_sienna_cichlid[cid][rw] : NULL;
                break;
        case IP_VERSION(2, 1, 2):
-               mmhub_cid = mmhub_client_ids_beige_goby[cid][rw];
+               mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_beige_goby) ?
+                       mmhub_client_ids_beige_goby[cid][rw] : NULL;
                break;
        default:
                mmhub_cid = NULL;