cpufreq/amd-pstate-ut: Drop policy reference before driver switch
Hello K Prateek Nayak,
Commit f9f16835d4dc ("cpufreq/amd-pstate-ut: Drop policy reference before driver switch") from May 8, 2026 (linux-next), leads to the following Smatch static checker warning:
drivers/cpufreq/amd-pstate-ut.c:308 amd_pstate_ut_epp() warn: pointer dereferenced without being set 'policy'
drivers/cpufreq/amd-pstate-ut.c
275 static int amd_pstate_ut_epp(u32 index)
276 {
277 static const char * const epp_strings[] = {
278 "power",
279 "balance_power",
280 "balance_performance",
281 "performance",
282 };
283 char *buf __free(cleanup_page) = NULL;
284 struct cpufreq_policy *policy = NULL;
285 enum amd_pstate_mode orig_mode;
286 struct amd_cpudata *cpudata;
287 unsigned long orig_policy;
288 bool orig_dynamic_epp;
289 int ret, cpu = 0;
290 u16 epp;
291 int i;
292
293 policy = cpufreq_cpu_get(cpu);
294 if (!policy)
295 return -ENODEV;
296
297 cpudata = policy->driver_data;
298 orig_mode = amd_pstate_get_status();
299 orig_dynamic_epp = cpudata->dynamic_epp;
300
301 /* Drop reference before potential driver change. */
302 cpufreq_cpu_put(policy);
303 policy = NULL;
^^^^^^^^^^^^^^policy set to NULL.
304
305 /* disable dynamic EPP before running test */
306 if (cpudata->dynamic_epp) {
307 pr_debug("Dynamic EPP is enabled, disabling it\n");
--> 308 amd_pstate_clear_dynamic_epp(policy);
^^^^^^So this will crash.
309 }
310
311 buf = (char *)__get_free_page(GFP_KERNEL);
312 if (!buf)
313 return -ENOMEM;
314
315 ret = amd_pstate_set_mode(AMD_PSTATE_ACTIVE);
316 if (ret)
317 goto out;
318 This email is a free service from the Smatch-CI project [smatch.sf.net].
regards,
dan carpenter
Hello Dan,
Quoted 6 lines · Dan Carpenter
301 /* Drop reference before potential driver change. */ 302 cpufreq_cpu_put(policy); 303 policy = NULL; ^^^^^^^^^^^^^^policy set to NULL.
Quoted 7 lines
304 305 /* disable dynamic EPP before running test */ 306 if (cpudata->dynamic_epp) { 307 pr_debug("Dynamic EPP is enabled, disabling it\n"); --> 308 amd_pstate_clear_dynamic_epp(policy); ^^^^^^So this will crash.
Blinks! I messed up that rebase pretty bad. Thank you for bringing it to my notice. I'll send a fix soon.
Quoted 1 line
This email is a free service from the Smatch-CI project [smatch.sf.net].
That is a useful service! Thanks a ton again. Running this against linux-next is much appreciated _/\_
Signature · 2 lines
Thanks and Regards, Prateek