[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6174bcc8-30f5-479b-bac6-f42eb1232b4d@kylinos.cn>
Date: Fri, 29 Aug 2025 09:09:18 +0800
From: Zihuan Zhang <zhangzihuan@...inos.cn>
To: "Rafael J. Wysocki" <rafael@...nel.org>
Cc: Viresh Kumar <viresh.kumar@...aro.org>,
Catalin Marinas <catalin.marinas@....com>, Will Deacon <will@...nel.org>,
Sean Christopherson <seanjc@...gle.com>, Paolo Bonzini
<pbonzini@...hat.com>, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, Markus Mayer
<mmayer@...adcom.com>, Florian Fainelli <florian.fainelli@...adcom.com>,
Srinivas Pandruvada <srinivas.pandruvada@...ux.intel.com>,
Madhavan Srinivasan <maddy@...ux.ibm.com>,
Michael Ellerman <mpe@...erman.id.au>, Krzysztof Kozlowski
<krzk@...nel.org>, Alim Akhtar <alim.akhtar@...sung.com>,
Thierry Reding <thierry.reding@...il.com>,
Jonathan Hunter <jonathanh@...dia.com>,
MyungJoo Ham <myungjoo.ham@...sung.com>,
Kyungmin Park <kyungmin.park@...sung.com>,
Chanwoo Choi <cw00.choi@...sung.com>,
Jani Nikula <jani.nikula@...ux.intel.com>,
Joonas Lahtinen <joonas.lahtinen@...ux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@...el.com>, Tvrtko Ursulin
<tursulin@...ulin.net>, David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>, Daniel Lezcano <daniel.lezcano@...nel.org>,
Sascha Hauer <s.hauer@...gutronix.de>, Shawn Guo <shawnguo@...nel.org>,
Eduardo Valentin <edubezval@...il.com>, Keerthy <j-keerthy@...com>,
Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>,
zhenglifeng <zhenglifeng1@...wei.com>, "H . Peter Anvin" <hpa@...or.com>,
Zhang Rui <rui.zhang@...el.com>, Len Brown <lenb@...nel.org>,
Nicholas Piggin <npiggin@...il.com>,
Christophe Leroy <christophe.leroy@...roup.eu>,
Lukasz Luba <lukasz.luba@....com>,
Pengutronix Kernel Team <kernel@...gutronix.de>,
Beata Michalska <beata.michalska@....com>, Fabio Estevam
<festevam@...il.com>, Pavel Machek <pavel@...nel.org>,
Sumit Gupta <sumitg@...dia.com>,
Prasanna Kumar T S M <ptsm@...ux.microsoft.com>,
Sudeep Holla <sudeep.holla@....com>, Yicong Yang <yangyicong@...ilicon.com>,
linux-pm@...r.kernel.org, x86@...nel.org, kvm@...r.kernel.org,
linux-acpi@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
linux-samsung-soc@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-tegra@...r.kernel.org, intel-gfx@...ts.freedesktop.org,
dri-devel@...ts.freedesktop.org, imx@...ts.linux.dev,
linux-omap@...r.kernel.org, linux-mediatek@...ts.infradead.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 03/18] ACPI: processor: thermal: Use
__free(put_cpufreq_policy) for policy reference
在 2025/8/28 17:40, Rafael J. Wysocki 写道:
> On Wed, Aug 27, 2025 at 4:33 AM Zihuan Zhang <zhangzihuan@...inos.cn> wrote:
>> 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 <zhangzihuan@...inos.cn>
>> ---
>> 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.
Thanks for pointing this out.
>> }
>>
>> 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).
Sorry for the mistake — I did this correctly in other places, but forgot
here.
> 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.
In fact, I have realized that we cannot always use __free for cleanup
directly.
The issue is that the release only happens at the end of the variable’s
lifetime, while in some cases we want to drop the reference immediately
after use.
To address this, I’m considering introducing a helper macro in
include/linux/cpufreq.h that would make this more explicit and allow
safe cleanup at the right point.
Before moving forward, I’d like to hear your opinion on this approach:
#define WITH_CPUFREQ_POLICY(cpu) \
for(struct cpufreq_policy *policy __free(put_cpufreq_policy) = \
cpufreq_cpu_get(cpu);;)
Then we can use it for all code :
WITH_CPUFREQ_POLICY(cpu) {
if(!policy)
return XXX; // error handing
//code use policy here
} // equal origin 'cpufreq_cpu_put' here
;;
//left code
>> 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",
>> --
Powered by blists - more mailing lists