Skip to contentSkip to conversation

drm/amd/pm: set min,max to 0 if there is no get_dpm_ultimate_freq function

PATCH In review [email protected] 2 participants 2 messages Jan 24, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/pm: set min,max to 0 if there is no get_dpm_ultimate_freq function

From: Tom Rix <[email protected]>

clang static analysis reports this represenative problem amdgpu_smu.c:144:18: warning: The left operand of '*' is a garbage value

        return clk_freq * 100;
               ~~~~~~~~ ^

If there is no get_dpm_ultimate_freq function, smu_get_dpm_freq_range returns success without setting the output min,max parameters. Because this is an extern function, set the min,max to 0 when there is no get_dpm_ultimate_freq.

Fixes e5ef784b1e17 ("drm/amd/powerplay: revise calling chain on retrieving frequency range")
---
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +7 -1
index 5ace30434e603..35fbe51f52eaa 100644
@@ -121,11 +121,17 @@ int smu_get_dpm_freq_range(struct smu_context *smu,
 	if (!min && !max)
 		return -EINVAL;
 
-	if (smu->ppt_funcs->get_dpm_ultimate_freq)
+	if (smu->ppt_funcs->get_dpm_ultimate_freq) {
 		ret = smu->ppt_funcs->get_dpm_ultimate_freq(smu,
 							    clk_type,
 							    min,
 							    max);
+	} else {
+		if (min)
+			*min = 0;
+		if (max)
+			*max = 0;
+	}
 
 	return ret;
 }
Signature · 1 line
2.26.3
#1 lore raw
Quoted 23 lines · On 1/24/2022 7:22 PM, [email protected] wrote:

From: Tom Rix <[email protected]>

clang static analysis reports this represenative problem amdgpu_smu.c:144:18: warning: The left operand of '*' is a garbage value

         return clk_freq * 100;
                ~~~~~~~~ ^

If there is no get_dpm_ultimate_freq function, smu_get_dpm_freq_range returns success without setting the output min,max parameters. Because this is an extern function, set the min,max to 0 when there is no get_dpm_ultimate_freq.

Fixes e5ef784b1e17 ("drm/amd/powerplay: revise calling chain on retrieving frequency range")
---
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
index 5ace30434e603..35fbe51f52eaa 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c int smu_get_dpm_freq_range(struct smu_context *smu, · line 129

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
@@ -121,11 +121,17 @@ int smu_get_dpm_freq_range(struct smu_context *smu,
  	if (!min && !max)
  		return -EINVAL;
 
-	if (smu->ppt_funcs->get_dpm_ultimate_freq)
+	if (smu->ppt_funcs->get_dpm_ultimate_freq) {
  		ret = smu->ppt_funcs->get_dpm_ultimate_freq(smu,
  							    clk_type,
  							    min,
  							    max);
+	} else {

return -ENOTSUPP; would be more appropriate.

Thanks,
Lijo

Quoted 9 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -0
+		if (min)
+			*min = 0;
+		if (max)
+			*max = 0;
+	}
 
  	return ret;
  }