drm/amdgpu: Use kvfree instead of kfree in amdgpu_gmc_get_nps_memranges()
authorZilin Guan <zilin@seu.edu.cn>
Thu, 29 Jan 2026 09:05:42 +0000 (09:05 +0000)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 5 Feb 2026 22:18:33 +0000 (17:18 -0500)
amdgpu_discovery_get_nps_info() internally allocates memory for ranges
using kvcalloc(), which may use vmalloc() for large allocation. Using
kfree() to release vmalloc memory will lead to a memory corruption.

Use kvfree() to safely handle both kmalloc and vmalloc allocations.

Compile tested only. Issue found using a prototype static analysis tool
and code review.

Fixes: b194d21b9bcc ("drm/amdgpu: Use NPS ranges from discovery table")
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c

index b793ce1..d35d971 100644 (file)
@@ -1436,7 +1436,7 @@ int amdgpu_gmc_get_nps_memranges(struct amdgpu_device *adev,
        if (!*exp_ranges)
                *exp_ranges = range_cnt;
 err:
-       kfree(ranges);
+       kvfree(ranges);
 
        return ret;
 }