drm/amdgpu: Fix uninitialized variable warning in amdgpu_info_ioctl
Subsystems (3)
PATCH 1/2 drm/amdgpu: Fix uninitialized variable warning in amdgpu_info_ioctl
Check the return value of amdgpu_xcp_get_inst_details, otherwise we may use an uninitialized variable inst_mask
Signed-off-by Ma Jun <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +9 -2
@@ -623,25 +623,32 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)switch (type) {case AMD_IP_BLOCK_TYPE_GFX : ret =amdgpu_xcp_get_inst_details (xcp,AMDGPU_XCP_GFX , &inst_mask); +if (ret) +return ret; count =hweight32 (inst_mask);break ;case AMD_IP_BLOCK_TYPE_SDMA : ret =amdgpu_xcp_get_inst_details (xcp,AMDGPU_XCP_SDMA , &inst_mask); +if (ret) +return ret; count =hweight32 (inst_mask);break ;case AMD_IP_BLOCK_TYPE_JPEG : ret =amdgpu_xcp_get_inst_details (xcp,AMDGPU_XCP_VCN , &inst_mask); +if (ret) +return ret; count =hweight32 (inst_mask) * adev->jpeg.num_jpeg_rings;break ;case AMD_IP_BLOCK_TYPE_VCN : ret =amdgpu_xcp_get_inst_details (xcp,AMDGPU_XCP_VCN , &inst_mask); +if (ret) +return ret; count =hweight32 (inst_mask);break ;default :return -EINVAL ; } -if (ret) -return ret; +return copy_to_user (out, &count,min (size,4u )) ? -EFAULT :0 ; }
Signature · 1 line
2.34.1
PATCH 2/2 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 <[email protected]>
--- drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c | 8 ++++---- drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c | 8 ++++---- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -4
@@ -929,7 +929,7 @@ static int pp_dpm_switch_power_profile(void *handle, enum PP_SMC_POWER_PROFILE type, bool en) {struct pp_hwmgr *hwmgr = handle; -long workload; +long workload[1 ];uint32_t index;if (!hwmgr || !hwmgr->pm_en)
@@ -947,12 +947,12 @@ static int pp_dpm_switch_power_profile(void *handle, hwmgr->workload_mask &= ~(1 << hwmgr->workload_prority[type]); index =fls (hwmgr->workload_mask); index = index >0 && index <= Workload_Policy_Max ? index -1 :0 ; - workload = hwmgr->workload_setting[index]; + workload[0 ] = hwmgr->workload_setting[index]; }else { hwmgr->workload_mask |= (1 << hwmgr->workload_prority[type]); index =fls (hwmgr->workload_mask); index = index <= Workload_Policy_Max ? index -1 :0 ; - workload = hwmgr->workload_setting[index]; + workload[0 ] = hwmgr->workload_setting[index]; } if (type == PP_SMC_POWER_PROFILE_COMPUTE &&
@@ -962,7 +962,7 @@ static int pp_dpm_switch_power_profile(void *handle, }if (hwmgr->dpm_level !=AMD_DPM_FORCED_LEVEL_MANUAL ) - hwmgr->hwmgr_func->set_power_profile_mode (hwmgr, &workload,0 ); + hwmgr->hwmgr_func->set_power_profile_mode (hwmgr, workload,0 );return 0 ; }
drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c +4 -4
@@ -269,7 +269,7 @@ int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, bool skip_display_set struct pp_power_state *new_ps) {uint32_t index; -long workload; +long workload[1 ];if (hwmgr->not_vf) {if (!skip_display_settings)
@@ -294,10 +294,10 @@ int psm_adjust_power_state_dynamic(struct pp_hwmgr *hwmgr, bool skip_display_setif (hwmgr->dpm_level !=AMD_DPM_FORCED_LEVEL_MANUAL ) { index =fls (hwmgr->workload_mask); index = index >0 && index <= Workload_Policy_Max ? index -1 :0 ; - workload = hwmgr->workload_setting[index]; + workload[0 ] = hwmgr->workload_setting[index]; -if (hwmgr->power_profile_mode != workload && hwmgr->hwmgr_func->set_power_profile_mode) - hwmgr->hwmgr_func->set_power_profile_mode (hwmgr, &workload,0 ); +if (hwmgr->power_profile_mode != workload[0 ] && hwmgr->hwmgr_func->set_power_profile_mode) + hwmgr->hwmgr_func->set_power_profile_mode (hwmgr, workload,0 ); }return 0 ;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +8 -8
@@ -2210,7 +2210,7 @@ static int smu_adjust_power_state_dynamic(struct smu_context *smu, {int ret =0 ;int index =0 ; -long workload; +long workload[1 ];struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);if (!skip_display_settings) {
@@ -2250,10 +2250,10 @@ static int smu_adjust_power_state_dynamic(struct smu_context *smu, smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM) { index =fls (smu->workload_mask); index = index >0 && index <=WORKLOAD_POLICY_MAX ? index -1 :0 ; - workload = smu->workload_setting[index]; + workload[0 ] = smu->workload_setting[index]; -if (smu->power_profile_mode != workload) -smu_bump_power_profile_mode (smu, &workload,0 ); +if (smu->power_profile_mode != workload[0 ]) +smu_bump_power_profile_mode (smu, workload,0 ); }return ret;
@@ -2303,7 +2303,7 @@ static int smu_switch_power_profile(void *handle, {struct smu_context *smu = handle;struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm); -long workload; +long workload[1 ];uint32_t index;if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
@@ -2316,17 +2316,17 @@ static int smu_switch_power_profile(void *handle, smu->workload_mask &= ~(1 << smu->workload_prority[type]); index =fls (smu->workload_mask); index = index >0 && index <=WORKLOAD_POLICY_MAX ? index -1 :0 ; - workload = smu->workload_setting[index]; + workload[0 ] = smu->workload_setting[index]; }else { smu->workload_mask |= (1 << smu->workload_prority[type]); index =fls (smu->workload_mask); index = index <=WORKLOAD_POLICY_MAX ? index -1 :0 ; - workload = smu->workload_setting[index]; + workload[0 ] = smu->workload_setting[index]; }if (smu_dpm_ctx->dpm_level !=AMD_DPM_FORCED_LEVEL_MANUAL && smu_dpm_ctx->dpm_level !=AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM ) -smu_bump_power_profile_mode (smu, &workload,0 ); +smu_bump_power_profile_mode (smu, workload,0 );return 0 ; }
Signature · 1 line
2.34.1
Quoted 5 lines · Ma Jun
Check the return value of
amdgpu_xcp_get_inst_details, otherwise we may use an uninitialized variableinst_maskSigned-off-by Ma Jun <[email protected]>
Acked-by Alex Deucher <[email protected]>
Quoted 46 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +9
-3@@ -623,25 +623,32 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)switch (type) {case AMD_IP_BLOCK_TYPE_GFX : ret =amdgpu_xcp_get_inst_details (xcp,AMDGPU_XCP_GFX , &inst_mask); +if (ret) +return ret; count =hweight32 (inst_mask);break ;case AMD_IP_BLOCK_TYPE_SDMA : ret =amdgpu_xcp_get_inst_details (xcp,AMDGPU_XCP_SDMA , &inst_mask); +if (ret) +return ret; count =hweight32 (inst_mask);break ;case AMD_IP_BLOCK_TYPE_JPEG : ret =amdgpu_xcp_get_inst_details (xcp,AMDGPU_XCP_VCN , &inst_mask); +if (ret) +return ret; count =hweight32 (inst_mask) * adev->jpeg.num_jpeg_rings;break ;case AMD_IP_BLOCK_TYPE_VCN : ret =amdgpu_xcp_get_inst_details (xcp,AMDGPU_XCP_VCN , &inst_mask); +if (ret) +return ret; count =hweight32 (inst_mask);break ;default :return -EINVAL ; } -if (ret) -return ret; +return copy_to_user (out, &count,min (size,4u )) ? -EFAULT :0 ; } --2.34.1