Skip to content

Commit 2167bb9

Browse files
Zihuan Zhangrafaeljw
authored andcommitted
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>
1 parent 9d68320 commit 2167bb9

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

drivers/acpi/processor_thermal.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,14 @@ static int phys_package_first_cpu(int cpu)
6262
return 0;
6363
}
6464

65-
static int cpu_has_cpufreq(unsigned int cpu)
65+
static bool cpu_has_cpufreq(unsigned int cpu)
6666
{
67-
struct cpufreq_policy *policy;
68-
6967
if (!acpi_processor_cpufreq_init)
7068
return 0;
7169

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;
7873
}
7974

8075
static int cpufreq_get_max_state(unsigned int cpu)
@@ -93,12 +88,31 @@ static int cpufreq_get_cur_state(unsigned int cpu)
9388
return reduction_step(cpu);
9489
}
9590

91+
static bool cpufreq_update_thermal_limit(unsigned int cpu, struct acpi_processor *pr)
92+
{
93+
unsigned long max_freq;
94+
int ret;
95+
96+
struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
97+
if (!policy)
98+
return false;
99+
100+
max_freq = (policy->cpuinfo.max_freq *
101+
(100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100;
102+
103+
ret = freq_qos_update_request(&pr->thermal_req, max_freq);
104+
if (ret < 0) {
105+
pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
106+
pr->id, ret);
107+
}
108+
109+
return true;
110+
}
111+
96112
static int cpufreq_set_cur_state(unsigned int cpu, int state)
97113
{
98-
struct cpufreq_policy *policy;
99114
struct acpi_processor *pr;
100-
unsigned long max_freq;
101-
int i, ret;
115+
int i;
102116

103117
if (!cpu_has_cpufreq(cpu))
104118
return 0;
@@ -120,20 +134,8 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
120134
if (unlikely(!freq_qos_request_active(&pr->thermal_req)))
121135
continue;
122136

123-
policy = cpufreq_cpu_get(i);
124-
if (!policy)
137+
if (!cpufreq_update_thermal_limit(i, pr))
125138
return -EINVAL;
126-
127-
max_freq = (policy->cpuinfo.max_freq *
128-
(100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100;
129-
130-
cpufreq_cpu_put(policy);
131-
132-
ret = freq_qos_update_request(&pr->thermal_req, max_freq);
133-
if (ret < 0) {
134-
pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
135-
pr->id, ret);
136-
}
137139
}
138140
return 0;
139141
}

0 commit comments

Comments
 (0)