The value should never exceed the array size as those
are the only values the hardware is expected to return,
but add checks anyway.

Signed-off-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c
index a72770e3d0e99..2532ca80f7356 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c
@@ -688,7 +688,8 @@ mmhub_v4_2_0_print_l2_protection_fault_status(struct 
amdgpu_device *adev,
                status);
        switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
        case IP_VERSION(4, 2, 0):
-               mmhub_cid = mmhub_client_ids_v4_2_0[cid][rw];
+               mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v4_2_0) ?
+                       mmhub_client_ids_v4_2_0[cid][rw] : NULL;
                break;
        default:
                mmhub_cid = NULL;
-- 
2.53.0

Reply via email to