]> www.infradead.org Git - users/hch/misc.git/commitdiff
ACPI: processor: thermal: Release policy references using __free()
authorZihuan Zhang <zhangzihuan@kylinos.cn>
Fri, 5 Sep 2025 13:24:09 +0000 (21:24 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 8 Sep 2025 17:53:32 +0000 (19:53 +0200)
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>
drivers/acpi/processor_thermal.c

index 1219adb11ab927cae52b8d106a09c2cb0f17f390..c7b1dc5687ecccceb7e3dcbdc861f54701aed58a 100644 (file)
@@ -62,19 +62,14 @@ static int phys_package_first_cpu(int cpu)
        return 0;
 }
 
-static int cpu_has_cpufreq(unsigned int cpu)
+static bool cpu_has_cpufreq(unsigned int cpu)
 {
-       struct cpufreq_policy *policy;
-
        if (!acpi_processor_cpufreq_init)
                return 0;
 
-       policy = cpufreq_cpu_get(cpu);
-       if (policy) {
-               cpufreq_cpu_put(policy);
-               return 1;
-       }
-       return 0;
+       struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
+
+       return policy != NULL;
 }
 
 static int cpufreq_get_max_state(unsigned int cpu)
@@ -93,12 +88,31 @@ static int cpufreq_get_cur_state(unsigned int cpu)
        return reduction_step(cpu);
 }
 
+static bool cpufreq_update_thermal_limit(unsigned int cpu, struct acpi_processor *pr)
+{
+       unsigned long max_freq;
+       int ret;
+
+       struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
+       if (!policy)
+               return false;
+
+       max_freq = (policy->cpuinfo.max_freq *
+               (100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100;
+
+       ret = freq_qos_update_request(&pr->thermal_req, max_freq);
+       if (ret < 0) {
+               pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
+                       pr->id, ret);
+       }
+
+       return true;
+}
+
 static int cpufreq_set_cur_state(unsigned int cpu, int state)
 {
-       struct cpufreq_policy *policy;
        struct acpi_processor *pr;
-       unsigned long max_freq;
-       int i, ret;
+       int i;
 
        if (!cpu_has_cpufreq(cpu))
                return 0;
@@ -120,20 +134,8 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
                if (unlikely(!freq_qos_request_active(&pr->thermal_req)))
                        continue;
 
-               policy = cpufreq_cpu_get(i);
-               if (!policy)
+               if (!cpufreq_update_thermal_limit(i, pr))
                        return -EINVAL;
-
-               max_freq = (policy->cpuinfo.max_freq *
-                           (100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100;
-
-               cpufreq_cpu_put(policy);
-
-               ret = freq_qos_update_request(&pr->thermal_req, max_freq);
-               if (ret < 0) {
-                       pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
-                               pr->id, ret);
-               }
        }
        return 0;
 }