drm/amd/pm: fix memleak issue in smu_v15_0_8_get_gpu_metrics()
Subsystems (3)
PATCH 1/3 drm/amd/pm: fix memleak issue in smu_v15_0_8_get_gpu_metrics()
remove unsued code to avoid memleak issue. (NOTE: This bug occurs during internal branch switching)
--- drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c +0 -2
@@ -1601,8 +1601,6 @@ static ssize_t smu_v15_0_8_get_gpu_metrics(struct smu_context *smu, void **tableuint32_t mid_mask = adev->aid_mask;MetricsTable_t *metrics; - metrics =kzalloc (sizeof (MetricsTable_t),GFP_KERNEL ); - ret =smu_v15_0_8_get_metrics_table_internal (smu,1 ,NULL );if (ret)return ret;
Signature · 1 line
2.47.3
PATCH 2/3 drm/amd/pm: fix null pointer dereference issue in smu_v15_0_8_get_power_limit()
Fix null pointer issues caused by coding errors
--- drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c +1 -1
@@ -1773,7 +1773,7 @@ static int smu_v15_0_8_get_power_limit(struct smu_context *smu, *current_power_limit = power_limit;if (default_power_limit) - *max_power_limit = pptable->MaxSocketPowerLimit; + *default_power_limit = pptable->MaxSocketPowerLimit;if (max_power_limit) *max_power_limit = pptable->MaxSocketPowerLimit;
Signature · 1 line
2.47.3
Re: [PATCH 2/3] drm/amd/pm: fix null pointer dereference issue in smu_v15_0_8_get_power_limit()
Quoted 5 lines · Yang Wang
Fix null pointer issues caused by coding errors
Fixes e4efa501f972 ("drm/amd/pm: add set{get}_power_limit support for smu 15.0.8")Signed-off-by Yang Wang <[email protected]>
Thanks,
Lijo
Quoted 17 lines
--- drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c +1
-1@@ -1773,7 +1773,7 @@ static int smu_v15_0_8_get_power_limit(struct smu_context *smu, *current_power_limit = power_limit;if (default_power_limit) - *max_power_limit = pptable->MaxSocketPowerLimit; + *default_power_limit = pptable->MaxSocketPowerLimit;if (max_power_limit) *max_power_limit = pptable->MaxSocketPowerLimit;
PATCH 3/3 drm/amd/pm: optimize logic and remove unnecessary checks in smu v15.0.8
In reply to Yang Wangthe following two sets of logic are clearly mutually exclusive in smu_v15_0_8_set_soft_freq_limited_range.
remove unnecessary code logic to keep the code logic clear.
e.g:
if (smu_dpm->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL)
return -EINVAL;
if (smu_dpm->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL) {
...
}--- .../drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c +23 -29
@@ -1899,42 +1899,36 @@ static int smu_v15_0_8_set_soft_freq_limited_range(struct smu_context *smu,if (smu_dpm->dpm_level !=AMD_DPM_FORCED_LEVEL_MANUAL )return -EINVAL ; -if (smu_dpm->dpm_level ==AMD_DPM_FORCED_LEVEL_MANUAL ) { -if (min >= max) { -dev_err (smu->adev->dev, -"Minimum clk should be less than the maximum allowed clock\n" ); -return -EINVAL ; - } +if (min >= max) { +dev_err (smu->adev->dev, +"Minimum clk should be less than the maximum allowed clock\n" ); +return -EINVAL ; + } -if (clk_type ==SMU_GFXCLK || clk_type ==SMU_SCLK ) { -if ((min == pstate_table->gfxclk_pstate.curr.min) && - (max == pstate_table->gfxclk_pstate.curr.max)) -return 0 ; +if (clk_type ==SMU_GFXCLK || clk_type ==SMU_SCLK ) { +if ((min == pstate_table->gfxclk_pstate.curr.min) && + (max == pstate_table->gfxclk_pstate.curr.max)) +return 0 ; - ret =smu_v15_0_8_set_gfx_soft_freq_limited_range (smu, - min, max); -if (!ret) { - pstate_table->gfxclk_pstate.curr.min = min; - pstate_table->gfxclk_pstate.curr.max = max; - } + ret =smu_v15_0_8_set_gfx_soft_freq_limited_range (smu, min, + max); +if (!ret) { + pstate_table->gfxclk_pstate.curr.min = min; + pstate_table->gfxclk_pstate.curr.max = max; } + } -if (clk_type ==SMU_UCLK ) { -if (max == pstate_table->uclk_pstate.curr.max) -return 0 ; - - ret =smu_v15_0_set_soft_freq_limited_range (smu, -SMU_UCLK , -0 , max, - false); -if (!ret) - pstate_table->uclk_pstate.curr.max = max; - } +if (clk_type ==SMU_UCLK ) { +if (max == pstate_table->uclk_pstate.curr.max) +return 0 ; -return ret; + ret =smu_v15_0_set_soft_freq_limited_range (smu,SMU_UCLK ,0 , + max, false); +if (!ret) + pstate_table->uclk_pstate.curr.max = max; } -return 0 ; +return ret; } static int smu_v15_0_8_od_edit_dpm_table(struct smu_context *smu,
Signature · 1 line
2.47.3
Re: [PATCH 3/3] drm/amd/pm: optimize logic and remove unnecessary checks in smu v15.0.8
Quoted 6 lines · Yang Wang
the following two sets of logic are clearly mutually exclusive in
smu_v15_0_8_set_soft_freq_limited_range.
remove unnecessary code logic to keep the code logic clear.e.g:
Quoted 8 lines
if (
smu_dpm->dpm_level!=AMD_DPM_FORCED_LEVEL_MANUAL)return -EINVAL;if (smu_dpm->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL) { ... }Fixes afb58cd13e81 ("drm/amd/pm: Add od_edit_dpm_table support")
I don't think there is any bug in this case. Only that the extra check is redundant.
Thanks,
Lijo
Quoted 76 lines
Signed-off-by Yang Wang <[email protected]>--- .../drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c +23
-29@@ -1899,42 +1899,36 @@ static int smu_v15_0_8_set_soft_freq_limited_range(struct smu_context *smu,if (smu_dpm->dpm_level !=AMD_DPM_FORCED_LEVEL_MANUAL )return -EINVAL ; -if (smu_dpm->dpm_level ==AMD_DPM_FORCED_LEVEL_MANUAL ) { -if (min >= max) { -dev_err (smu->adev->dev, -"Minimum clk should be less than the maximum allowed clock\n" ); -return -EINVAL ; - } +if (min >= max) { +dev_err (smu->adev->dev, +"Minimum clk should be less than the maximum allowed clock\n" ); +return -EINVAL ; + } -if (clk_type ==SMU_GFXCLK || clk_type ==SMU_SCLK ) { -if ((min == pstate_table->gfxclk_pstate.curr.min) && - (max == pstate_table->gfxclk_pstate.curr.max)) -return 0 ; +if (clk_type ==SMU_GFXCLK || clk_type ==SMU_SCLK ) { +if ((min == pstate_table->gfxclk_pstate.curr.min) && + (max == pstate_table->gfxclk_pstate.curr.max)) +return 0 ; - ret =smu_v15_0_8_set_gfx_soft_freq_limited_range (smu, - min, max); -if (!ret) { - pstate_table->gfxclk_pstate.curr.min = min; - pstate_table->gfxclk_pstate.curr.max = max; - } + ret =smu_v15_0_8_set_gfx_soft_freq_limited_range (smu, min, + max); +if (!ret) { + pstate_table->gfxclk_pstate.curr.min = min; + pstate_table->gfxclk_pstate.curr.max = max; } + } -if (clk_type ==SMU_UCLK ) { -if (max == pstate_table->uclk_pstate.curr.max) -return 0 ; - - ret =smu_v15_0_set_soft_freq_limited_range (smu, -SMU_UCLK , -0 , max, - false); -if (!ret) - pstate_table->uclk_pstate.curr.max = max; - } +if (clk_type ==SMU_UCLK ) { +if (max == pstate_table->uclk_pstate.curr.max) +return 0 ; -return ret; + ret =smu_v15_0_set_soft_freq_limited_range (smu,SMU_UCLK ,0 , + max, false); +if (!ret) + pstate_table->uclk_pstate.curr.max = max; } -return 0 ; +return ret; } static int smu_v15_0_8_od_edit_dpm_table(struct smu_context *smu,
Quoted 7 lines · Yang Wang
remove unsued code to avoid memleak issue. (NOTE: This bug occurs during internal branch switching)
Fixes 60c033841eb9 ("drm/amd/pm: add get_gpu_metrics support for 15.0.8")Signed-off-by Yang Wang <[email protected]>
Quoted 20 lines
--- drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c | 2 -- 1 file changed, 2 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c +0
-3@@ -1601,8 +1601,6 @@ static ssize_t smu_v15_0_8_get_gpu_metrics(struct smu_context *smu, void **tableuint32_t mid_mask = adev->aid_mask;MetricsTable_t *metrics; - metrics =kzalloc (sizeof (MetricsTable_t),GFP_KERNEL ); - ret =smu_v15_0_8_get_metrics_table_internal (smu,1 ,NULL );if (ret)return ret; --2.47.3