drm/amdgpu: Fix the warning division or modulo by zero
authorJesse Zhang <jesse.zhang@amd.com>
Fri, 10 May 2024 09:32:53 +0000 (17:32 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 13 May 2024 20:11:47 +0000 (16:11 -0400)
Checks the partition mode and returns an error for an invalid mode.

Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
Suggested-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c

index 414ea3f560a7a54b72ffce7290c1d41ed126798c..d62cfa4e2d2b426009321d6fe0c3c3d5a838df8b 100644 (file)
@@ -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 config, no compatible compute partition mode found, available memory partitions: %d",
+                               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",