2626#include <linux/module.h>
2727#include <linux/moduleparam.h>
2828#include <linux/fs.h>
29+ #include <linux/cleanup.h>
2930
3031#include <acpi/cppc_acpi.h>
3132
@@ -127,11 +128,12 @@ static void amd_pstate_ut_check_perf(u32 index)
127128 u32 highest_perf = 0 , nominal_perf = 0 , lowest_nonlinear_perf = 0 , lowest_perf = 0 ;
128129 u64 cap1 = 0 ;
129130 struct cppc_perf_caps cppc_perf ;
130- struct cpufreq_policy * policy = NULL ;
131131 struct amd_cpudata * cpudata = NULL ;
132132 union perf_cached cur_perf ;
133133
134134 for_each_possible_cpu (cpu ) {
135+ struct cpufreq_policy * policy __free (put_cpufreq_policy ) = NULL ;
136+
135137 policy = cpufreq_cpu_get (cpu );
136138 if (!policy )
137139 break ;
@@ -142,7 +144,7 @@ static void amd_pstate_ut_check_perf(u32 index)
142144 if (ret ) {
143145 amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
144146 pr_err ("%s cppc_get_perf_caps ret=%d error!\n" , __func__ , ret );
145- goto skip_test ;
147+ return ;
146148 }
147149
148150 highest_perf = cppc_perf .highest_perf ;
@@ -154,7 +156,7 @@ static void amd_pstate_ut_check_perf(u32 index)
154156 if (ret ) {
155157 amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
156158 pr_err ("%s read CPPC_CAP1 ret=%d error!\n" , __func__ , ret );
157- goto skip_test ;
159+ return ;
158160 }
159161
160162 highest_perf = AMD_CPPC_HIGHEST_PERF (cap1 );
@@ -167,7 +169,7 @@ static void amd_pstate_ut_check_perf(u32 index)
167169 if (highest_perf != cur_perf .highest_perf && !cpudata -> hw_prefcore ) {
168170 pr_err ("%s cpu%d highest=%d %d highest perf doesn't match\n" ,
169171 __func__ , cpu , highest_perf , cur_perf .highest_perf );
170- goto skip_test ;
172+ return ;
171173 }
172174 if (nominal_perf != cur_perf .nominal_perf ||
173175 (lowest_nonlinear_perf != cur_perf .lowest_nonlinear_perf ) ||
@@ -177,7 +179,7 @@ static void amd_pstate_ut_check_perf(u32 index)
177179 __func__ , cpu , nominal_perf , cur_perf .nominal_perf ,
178180 lowest_nonlinear_perf , cur_perf .lowest_nonlinear_perf ,
179181 lowest_perf , cur_perf .lowest_perf );
180- goto skip_test ;
182+ return ;
181183 }
182184
183185 if (!((highest_perf >= nominal_perf ) &&
@@ -188,15 +190,11 @@ static void amd_pstate_ut_check_perf(u32 index)
188190 pr_err ("%s cpu%d highest=%d >= nominal=%d > lowest_nonlinear=%d > lowest=%d > 0, the formula is incorrect!\n" ,
189191 __func__ , cpu , highest_perf , nominal_perf ,
190192 lowest_nonlinear_perf , lowest_perf );
191- goto skip_test ;
193+ return ;
192194 }
193- cpufreq_cpu_put (policy );
194195 }
195196
196197 amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_PASS ;
197- return ;
198- skip_test :
199- cpufreq_cpu_put (policy );
200198}
201199
202200/*
@@ -207,10 +205,11 @@ static void amd_pstate_ut_check_perf(u32 index)
207205static void amd_pstate_ut_check_freq (u32 index )
208206{
209207 int cpu = 0 ;
210- struct cpufreq_policy * policy = NULL ;
211208 struct amd_cpudata * cpudata = NULL ;
212209
213210 for_each_possible_cpu (cpu ) {
211+ struct cpufreq_policy * policy __free (put_cpufreq_policy ) = NULL ;
212+
214213 policy = cpufreq_cpu_get (cpu );
215214 if (!policy )
216215 break ;
@@ -224,14 +223,14 @@ static void amd_pstate_ut_check_freq(u32 index)
224223 pr_err ("%s cpu%d max=%d >= nominal=%d > lowest_nonlinear=%d > min=%d > 0, the formula is incorrect!\n" ,
225224 __func__ , cpu , policy -> cpuinfo .max_freq , cpudata -> nominal_freq ,
226225 cpudata -> lowest_nonlinear_freq , policy -> cpuinfo .min_freq );
227- goto skip_test ;
226+ return ;
228227 }
229228
230229 if (cpudata -> lowest_nonlinear_freq != policy -> min ) {
231230 amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
232231 pr_err ("%s cpu%d cpudata_lowest_nonlinear_freq=%d policy_min=%d, they should be equal!\n" ,
233232 __func__ , cpu , cpudata -> lowest_nonlinear_freq , policy -> min );
234- goto skip_test ;
233+ return ;
235234 }
236235
237236 if (cpudata -> boost_supported ) {
@@ -243,20 +242,16 @@ static void amd_pstate_ut_check_freq(u32 index)
243242 pr_err ("%s cpu%d policy_max=%d should be equal cpu_max=%d or cpu_nominal=%d !\n" ,
244243 __func__ , cpu , policy -> max , policy -> cpuinfo .max_freq ,
245244 cpudata -> nominal_freq );
246- goto skip_test ;
245+ return ;
247246 }
248247 } else {
249248 amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_FAIL ;
250249 pr_err ("%s cpu%d must support boost!\n" , __func__ , cpu );
251- goto skip_test ;
250+ return ;
252251 }
253- cpufreq_cpu_put (policy );
254252 }
255253
256254 amd_pstate_ut_cases [index ].result = AMD_PSTATE_UT_RESULT_PASS ;
257- return ;
258- skip_test :
259- cpufreq_cpu_put (policy );
260255}
261256
262257static int amd_pstate_set_mode (enum amd_pstate_mode mode )
0 commit comments