summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorAsad Kamal <asad.kamal@amd.com>2026-06-16 22:25:08 +0800
committerAlex Deucher <alexander.deucher@amd.com>2026-07-01 11:08:56 -0400
commita101cfbd2771199af1396954f5bb007df94cebb0 (patch)
treecf27f09d1ced0e5f539e237d86b180a235ce5139 /drivers
parent0eda57ee303b4392057b7d4c32e8fda9d14cffad (diff)
downloadlinux-next-a101cfbd2771199af1396954f5bb007df94cebb0.tar.gz
linux-next-a101cfbd2771199af1396954f5bb007df94cebb0.zip
drm/amdgpu: guard zero divisors in soc_v1_0 partition code
Abort driver load when num_mem_partitions is zero since operation is unreliable without valid memory partition info. Skip absent resources in soc_v1_0_get_xcp_res_info() to avoid divide-by-zero on firmware- reported zero instance counts. v2: Remove redundant checks (Lijo) v3: Return error instead when num_mem_partitions is zero (Lijo) Signed-off-by: Asad Kamal <asad.kamal@amd.com> Reviewed-by: Lijo Lazar <lijo.lazar@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c9
-rw-r--r--drivers/gpu/drm/amd/amdgpu/soc_v1_0.c4
2 files changed, 10 insertions, 3 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index 5f7745143f56..aeda54ee2c9d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -1761,10 +1761,15 @@ int amdgpu_gmc_init_mem_ranges(struct amdgpu_device *adev)
valid = true;
else
valid = amdgpu_gmc_validate_partition_info(adev);
- if (!valid) {
- /* TODO: handle invalid case */
+ if (!valid)
dev_warn(adev->dev,
"Mem ranges not matching with hardware config\n");
+
+ if (!adev->gmc.num_mem_partitions) {
+ dev_err(adev->dev, "num_mem_partitions is zero\n");
+ kfree(adev->gmc.mem_partitions);
+ adev->gmc.mem_partitions = NULL;
+ return -EINVAL;
}
return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/soc_v1_0.c b/drivers/gpu/drm/amd/amdgpu/soc_v1_0.c
index 5f05c8e68297..f3f3fac435d1 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc_v1_0.c
@@ -600,8 +600,10 @@ static int soc_v1_0_get_xcp_res_info(struct amdgpu_xcp_mgr *xcp_mgr,
xcp_cfg->num_res = ARRAY_SIZE(max_res);
for (i = 0; i < xcp_cfg->num_res; i++) {
- res_lt_xcp = max_res[i] < num_xcp;
xcp_cfg->xcp_res[i].id = i;
+ if (!max_res[i])
+ continue;
+ res_lt_xcp = max_res[i] < num_xcp;
xcp_cfg->xcp_res[i].num_inst =
res_lt_xcp ? 1 : max_res[i] / num_xcp;
xcp_cfg->xcp_res[i].num_inst =