Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ACPI: processor: thermal: Release policy references using __free()

Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy)
for policy references. This reduces the risk of reference counting
mistakes and aligns the code with the latest kernel style.

No functional change intended.

Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
Link: https://patch.msgid.link/20250905132413.1376220-3-zhangzihuan@kylinos.cn
[ rjw: Subject and changelog edits, whitespace fixups ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Zihuan Zhang and committed by
Rafael J. Wysocki
2167bb92 9d68320b

+27 -25
+27 -25
drivers/acpi/processor_thermal.c
··· 62 62 return 0; 63 63 } 64 64 65 - static int cpu_has_cpufreq(unsigned int cpu) 65 + static bool cpu_has_cpufreq(unsigned int cpu) 66 66 { 67 - struct cpufreq_policy *policy; 68 - 69 67 if (!acpi_processor_cpufreq_init) 70 68 return 0; 71 69 72 - policy = cpufreq_cpu_get(cpu); 73 - if (policy) { 74 - cpufreq_cpu_put(policy); 75 - return 1; 76 - } 77 - return 0; 70 + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu); 71 + 72 + return policy != NULL; 78 73 } 79 74 80 75 static int cpufreq_get_max_state(unsigned int cpu) ··· 88 93 return reduction_step(cpu); 89 94 } 90 95 96 + static bool cpufreq_update_thermal_limit(unsigned int cpu, struct acpi_processor *pr) 97 + { 98 + unsigned long max_freq; 99 + int ret; 100 + 101 + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu); 102 + if (!policy) 103 + return false; 104 + 105 + max_freq = (policy->cpuinfo.max_freq * 106 + (100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100; 107 + 108 + ret = freq_qos_update_request(&pr->thermal_req, max_freq); 109 + if (ret < 0) { 110 + pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n", 111 + pr->id, ret); 112 + } 113 + 114 + return true; 115 + } 116 + 91 117 static int cpufreq_set_cur_state(unsigned int cpu, int state) 92 118 { 93 - struct cpufreq_policy *policy; 94 119 struct acpi_processor *pr; 95 - unsigned long max_freq; 96 - int i, ret; 120 + int i; 97 121 98 122 if (!cpu_has_cpufreq(cpu)) 99 123 return 0; ··· 134 120 if (unlikely(!freq_qos_request_active(&pr->thermal_req))) 135 121 continue; 136 122 137 - policy = cpufreq_cpu_get(i); 138 - if (!policy) 123 + if (!cpufreq_update_thermal_limit(i, pr)) 139 124 return -EINVAL; 140 - 141 - max_freq = (policy->cpuinfo.max_freq * 142 - (100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100; 143 - 144 - cpufreq_cpu_put(policy); 145 - 146 - ret = freq_qos_update_request(&pr->thermal_req, max_freq); 147 - if (ret < 0) { 148 - pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n", 149 - pr->id, ret); 150 - } 151 125 } 152 126 return 0; 153 127 }