Skip to contentSkip to conversation

drm/amd/pm: fix memleak issue in smu_v15_0_8_get_gpu_metrics()

PATCH In review Yang Wang 3 participants 6 messages Mar 31

Subsystems (3)
lore
Share & tools
lore

Yang Wang

author
#0 lore raw

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)

Fixes 60c033841eb9 ("drm/amd/pm: add get_gpu_metrics support for 15.0.8")
---
 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
index 89a44b456e8a..b158be7cd7bc 100644
@@ -1601,8 +1601,6 @@ static ssize_t smu_v15_0_8_get_gpu_metrics(struct smu_context *smu, void **table
 	uint32_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
author
#1 lore raw

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

Fixes e4efa501f972 ("drm/amd/pm: add set{get}_power_limit support for smu 15.0.8")
---
 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
index b158be7cd7bc..ae43edfa93a5 100644
@@ -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
Reviewed-by on v1 2/3
#2 lore raw

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")

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
index b158be7cd7bc..ae43edfa93a5 100644
@@ -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;
author
#3 lore raw

PATCH 3/3 drm/amd/pm: optimize logic and remove unnecessary checks in smu v15.0.8

In reply to 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:

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")
---
 .../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
index ae43edfa93a5..a916cad40dbc 100644
@@ -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
Reviewed-by on v1 3/3
#4 lore raw

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
---
  .../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
index ae43edfa93a5..a916cad40dbc 100644
@@ -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,
Acked-by on v1 1/3
#5 lore raw
In reply to Yang Wang
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")
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
index 89a44b456e8a..b158be7cd7bc 100644
@@ -1601,8 +1601,6 @@ static ssize_t smu_v15_0_8_get_gpu_metrics(struct smu_context *smu, void **table
        uint32_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