]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Sep 2024 09:06:40 +0000 (11:06 +0200)
[ Upstream commit df0a9bd92fbbd3fcafcb2bce6463c9228a3e6868 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c

index 5e72b7555edae9ffbeca62b1d2a7ef0b2874ba3b..3673a9e7ba44990d0a0217abdf1be0008345ea77 100644 (file)
@@ -5190,7 +5190,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 57a354a03e8aef0ce00c75ff80db3bb96d9395d6..a55dc6ec4f7667c2d97a2da17c87f94a2e4ab7b7 100644 (file)
@@ -4095,9 +4095,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,
@@ -4159,6 +4161,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,