Skip to content

Commit f683f24

Browse files
Ma Junalexdeucher
authored andcommitted
drm/amdgpu/pm: Fix the param type of set_power_profile_mode
Function .set_power_profile_mode need an array as input parameter. So define variable workload as an array to fix the below coverity warning. "Passing &workload to function hwmgr->hwmgr_func->set_power_profile_mode which uses it as an array. This might corrupt or misinterpret adjacent memory locations" Signed-off-by: Ma Jun <Jun.Ma2@amd.com> Acked-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 0991e49 commit f683f24

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ static int pp_dpm_switch_power_profile(void *handle,
929929
enum PP_SMC_POWER_PROFILE type, bool en)
930930
{
931931
struct pp_hwmgr *hwmgr = handle;
932-
long workload;
932+
long workload[1];
933933
uint32_t index;
934934

935935
if (!hwmgr || !hwmgr->pm_en)
@@ -947,12 +947,12 @@ static int pp_dpm_switch_power_profile(void *handle,
947947
hwmgr->workload_mask &= ~(1 << hwmgr->workload_prority[type]);
948948
index = fls(hwmgr->workload_mask);
949949
index = index > 0 && index <= Workload_Policy_Max ? index - 1 : 0;
950-
workload = hwmgr->workload_setting[index];
950+
workload[0] = hwmgr->workload_setting[index];
951951
} else {
952952
hwmgr->workload_mask |= (1 << hwmgr->workload_prority[type]);
953953
index = fls(hwmgr->workload_mask);
954954
index = index <= Workload_Policy_Max ? index - 1 : 0;
955-
workload = hwmgr->workload_setting[index];
955+
workload[0] = hwmgr->workload_setting[index];
956956
}
957957

958958
if (type == PP_SMC_POWER_PROFILE_COMPUTE &&
@@ -962,7 +962,7 @@ static int pp_dpm_switch_power_profile(void *handle,
962962
}
963963

964964
if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL)
965-
hwmgr->hwmgr_func->set_power_profile_mode(hwmgr, &workload, 0);
965+
hwmgr->hwmgr_func->set_power_profile_mode(hwmgr, workload, 0);
966966

967967
return 0;
968968
}

drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, bool skip_display_set
269269
struct pp_power_state *new_ps)
270270
{
271271
uint32_t index;
272-
long workload;
272+
long workload[1];
273273

274274
if (hwmgr->not_vf) {
275275
if (!skip_display_settings)
@@ -294,10 +294,10 @@ int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, bool skip_display_set
294294
if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
295295
index = fls(hwmgr->workload_mask);
296296
index = index > 0 && index <= Workload_Policy_Max ? index - 1 : 0;
297-
workload = hwmgr->workload_setting[index];
297+
workload[0] = hwmgr->workload_setting[index];
298298

299-
if (hwmgr->power_profile_mode != workload && hwmgr->hwmgr_func->set_power_profile_mode)
300-
hwmgr->hwmgr_func->set_power_profile_mode(hwmgr, &workload, 0);
299+
if (hwmgr->power_profile_mode != workload[0] && hwmgr->hwmgr_func->set_power_profile_mode)
300+
hwmgr->hwmgr_func->set_power_profile_mode(hwmgr, workload, 0);
301301
}
302302

303303
return 0;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ static int smu_adjust_power_state_dynamic(struct smu_context *smu,
22102210
{
22112211
int ret = 0;
22122212
int index = 0;
2213-
long workload;
2213+
long workload[1];
22142214
struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
22152215

22162216
if (!skip_display_settings) {
@@ -2250,10 +2250,10 @@ static int smu_adjust_power_state_dynamic(struct smu_context *smu,
22502250
smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM) {
22512251
index = fls(smu->workload_mask);
22522252
index = index > 0 && index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;
2253-
workload = smu->workload_setting[index];
2253+
workload[0] = smu->workload_setting[index];
22542254

2255-
if (smu->power_profile_mode != workload)
2256-
smu_bump_power_profile_mode(smu, &workload, 0);
2255+
if (smu->power_profile_mode != workload[0])
2256+
smu_bump_power_profile_mode(smu, workload, 0);
22572257
}
22582258

22592259
return ret;
@@ -2303,7 +2303,7 @@ static int smu_switch_power_profile(void *handle,
23032303
{
23042304
struct smu_context *smu = handle;
23052305
struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
2306-
long workload;
2306+
long workload[1];
23072307
uint32_t index;
23082308

23092309
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
@@ -2316,17 +2316,17 @@ static int smu_switch_power_profile(void *handle,
23162316
smu->workload_mask &= ~(1 << smu->workload_prority[type]);
23172317
index = fls(smu->workload_mask);
23182318
index = index > 0 && index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;
2319-
workload = smu->workload_setting[index];
2319+
workload[0] = smu->workload_setting[index];
23202320
} else {
23212321
smu->workload_mask |= (1 << smu->workload_prority[type]);
23222322
index = fls(smu->workload_mask);
23232323
index = index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;
2324-
workload = smu->workload_setting[index];
2324+
workload[0] = smu->workload_setting[index];
23252325
}
23262326

23272327
if (smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL &&
23282328
smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM)
2329-
smu_bump_power_profile_mode(smu, &workload, 0);
2329+
smu_bump_power_profile_mode(smu, workload, 0);
23302330

23312331
return 0;
23322332
}

0 commit comments

Comments
 (0)