]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdgpu/pm: Check input value for CUSTOM profile mode setting on legacy SOCs
authorMa Jun <Jun.Ma2@amd.com>
Fri, 10 May 2024 02:05:21 +0000 (10:05 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 13 May 2024 19:44:52 +0000 (15:44 -0400)
Check the input value for CUSTOM profile mode setting on legacy
SOCs. Otherwise we may use uninitalized value of input[]

Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
Reviewed-by: Yang Wang <kevinyang.wang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c

index 5c95eda6cbd2ee9bbaf5d1ab5fc1f59e4fb8cc05..52ac95f8a84f09fced0ec1ab8ac86f79423fe3d9 100644 (file)
@@ -5647,7 +5647,7 @@ static int smu7_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, uint
        mode = input[size];
        switch (mode) {
        case PP_SMC_POWER_PROFILE_CUSTOM:
-               if (size < 8 && size != 0)
+               if (size != 8 && size != 0)
                        return -EINVAL;
                /* If only CUSTOM is passed in, use the saved values. Check
                 * that we actually have a CUSTOM profile by ensuring that
index bf1b829f9d68fb6a8722a60fd60f7494d202433e..baf251fe5d8289013dcb79451a7e3fdf3dbb46b2 100644 (file)
@@ -4102,9 +4102,11 @@ static int vega20_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, ui
        if (power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
                struct vega20_hwmgr *data =
                        (struct vega20_hwmgr *)(hwmgr->backend);
-               if (size == 0 && !data->is_custom_profile_set)
+
+               if (size != 10 && size != 0)
                        return -EINVAL;
-               if (size < 10 && size != 0)
+
+               if (size == 0 && !data->is_custom_profile_set)
                        return -EINVAL;
 
                result = vega20_get_activity_monitor_coeff(hwmgr,
@@ -4166,6 +4168,8 @@ static int vega20_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, ui
                        activity_monitor.Fclk_PD_Data_error_coeff = input[8];
                        activity_monitor.Fclk_PD_Data_error_rate_coeff = input[9];
                        break;
+               default:
+                       return -EINVAL;
                }
 
                result = vega20_set_activity_monitor_coeff(hwmgr,