Skip to content

Commit

Permalink
drm/amdgpu: Fix off by one in current_memory_partition_show()
Browse files Browse the repository at this point in the history
The >= ARRAY_SIZE() should be > ARRAY_SIZE() to prevent an out of
bounds read.

Fixes: 012be6f ("drm/amdgpu: Add sysfs interfaces for NPS mode")
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
  • Loading branch information
Dan Carpenter authored and Alex Deucher committed Oct 15, 2024
1 parent 336568d commit 9f7e94a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ static ssize_t current_memory_partition_show(
enum amdgpu_memory_partition mode;

mode = adev->gmc.gmc_funcs->query_mem_partition_mode(adev);
if ((mode > ARRAY_SIZE(nps_desc)) ||
if ((mode >= ARRAY_SIZE(nps_desc)) ||
(BIT(mode) & AMDGPU_ALL_NPS_MASK) != BIT(mode))
return sysfs_emit(buf, "UNKNOWN\n");

Expand Down

0 comments on commit 9f7e94a

Please sign in to comment.