Skip to contentSkip to conversation

drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

PATCH In review Jesse Zhang 2 participants 2 messages May 10, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 19/22 drm/amdgpu: Fix the warning division or modulo by zero for the variable num_xcc_per_xcp

Checks the partition mode and returns an error for an invalid mode.

---
 drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +6 -0
index 414ea3f560a7..b1c18b7a38ad 100644
@@ -501,6 +501,12 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr,
 
 	if (mode == AMDGPU_AUTO_COMPUTE_PARTITION_MODE) {
 		mode = __aqua_vanjaram_get_auto_mode(xcp_mgr);
+		if (mode == AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE) {
+			dev_err(adev->dev,
+				"Invalid compute partition mode requested, requested: %s, available memory partitions: %d",
+				amdgpu_gfx_compute_mode_desc(mode), adev->gmc.num_mem_partitions);
+			return -EINVAL;
+		}
 	} else if (!__aqua_vanjaram_is_valid_mode(xcp_mgr, mode)) {
 		dev_err(adev->dev,
 			"Invalid compute partition mode requested, requested: %s, available memory partitions: %d",
@@ -522,6 +528,7 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr,
 		goto unlock;
 
 	num_xcc_per_xcp = __aqua_vanjaram_get_xcc_per_xcp(xcp_mgr, mode);
 	if (adev->gfx.funcs->switch_partition_mode)
 		adev->gfx.funcs->switch_partition_mode(xcp_mgr->adev,
 						       num_xcc_per_xcp);
Signature · 1 line
2.25.1
Reviewed-by on v2 19/22
#1 lore raw
Quoted 13 lines · Jesse Zhang

Checks the partition mode and returns an error for an invalid mode.

---
 drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +0 -0
index 414ea3f560a7..b1c18b7a38ad 100644

drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr, · line 506

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +3 -0
@@ -501,6 +501,12 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr,
 
 	if (mode == AMDGPU_AUTO_COMPUTE_PARTITION_MODE) {
 		mode = __aqua_vanjaram_get_auto_mode(xcp_mgr);
+		if (mode == AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE) {
+			dev_err(adev->dev,
+				"Invalid compute partition mode requested, requested: %s, available memory partitions: %d",

Please change the error message to something like

"Invalid config, no compatible compute partition mode found, available memory partitions: %d"

With that change,

Thanks,
Lijo

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +3 -0
+				amdgpu_gfx_compute_mode_desc(mode), adev->gmc.num_mem_partitions);
+			return -EINVAL;
+		}
 	} else if (!__aqua_vanjaram_is_valid_mode(xcp_mgr, mode)) {
 		dev_err(adev->dev,
 			"Invalid compute partition mode requested, requested: %s, available memory partitions: %d",
@@ -522,6 +528,7 @@ static int aqua_vanjaram_switch_partition_mode(struct amdgpu_xcp_mgr *xcp_mgr,
 		goto unlock;
 
 	num_xcc_per_xcp = __aqua_vanjaram_get_xcc_per_xcp(xcp_mgr, mode);
 	if (adev->gfx.funcs->switch_partition_mode)
 		adev->gfx.funcs->switch_partition_mode(xcp_mgr->adev,
 						       num_xcc_per_xcp);