Re: [PATCH v2 03/18] ACPI: processor: thermal: Use __free(put_cpufreq_policy) for policy reference

From
Rafael J. Wysocki <rafael@kernel.org>
Date
2025-08-28 09:40:16
Also in
dri-devel, imx, intel-gfx, kvm, linux-acpi, linux-mediatek, linux-omap, linux-pm, linux-samsung-soc, linux-tegra, lkml
Reply to
Zihuan Zhang, 2025-08-27
On Wed, Aug 27, 2025 at 4:33 AM Zihuan Zhang [off-list ref] wrote:
quoted hunk ↗ jump to hunk
Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy)
annotation 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 <redacted>
---
 drivers/acpi/processor_thermal.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index 1219adb11ab9..f99ed0812934 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -64,17 +64,13 @@ static int phys_package_first_cpu(int cpu)

 static int cpu_has_cpufreq(unsigned int cpu)
 {
-       struct cpufreq_policy *policy;
+       struct cpufreq_policy *policy __free(put_cpufreq_policy);

        if (!acpi_processor_cpufreq_init)
                return 0;

        policy = cpufreq_cpu_get(cpu);
-       if (policy) {
-               cpufreq_cpu_put(policy);
-               return 1;
-       }
-       return 0;
+       return !!policy;
If you want to make this change, please also change the return type of
the function to bool.
quoted hunk ↗ jump to hunk
 }

 static int cpufreq_get_max_state(unsigned int cpu)
@@ -95,7 +91,7 @@ static int cpufreq_get_cur_state(unsigned int cpu)

 static int cpufreq_set_cur_state(unsigned int cpu, int state)
 {
-       struct cpufreq_policy *policy;
+       struct cpufreq_policy *policy __free(put_cpufreq_policy);
This isn't correct AFAICS at least formally because the scope of the
variable is the whole function, so it won't get out of scope at the
point where you want cpufreq_cpu_put() to be called.

The policy variable should be defined in the block following the "for"
loop (and actually all of the local variables except for "i" can be
defined there).

Or better still, please move that block to a separate function
containing all of the requisite local variable definitions and call
that function for each online CPU.
quoted hunk ↗ jump to hunk
        struct acpi_processor *pr;
        unsigned long max_freq;
        int i, ret;
@@ -127,8 +123,6 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
                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",
--
  
Thread (39 messages) 39 messages, 6 authors, last reply 2025-08-29
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help