[PATCH v4 02/10] ACPI: processor: thermal: Use scope-based cleanup helper
Jonathan Cameron
jonathan.cameron at huawei.com
Fri Sep 5 19:45:21 AEST 2025
On Wed, 3 Sep 2025 15:23:31 +0200
"Rafael J. Wysocki" <rafael at kernel.org> wrote:
> On Wed, Sep 3, 2025 at 3:18 PM Zihuan Zhang <zhangzihuan at kylinos.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 at kylinos.cn>
> > ---
> > drivers/acpi/processor_thermal.c | 37 ++++++++++++++++++--------------
> > 1 file changed, 21 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
> > index 1219adb11ab9..5043f17d27b7 100644
> > --- a/drivers/acpi/processor_thermal.c
> > +++ b/drivers/acpi/processor_thermal.c
> > @@ -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;
> > + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
I'd put the order back as it was. See docs in cleanup.h, it is fine to
declare local variables inline if they are being use with __free()
That way if the simple check on acpi_process_cpu_freq_init fails no
get needs to occur.
So something like
static bool cpu_has_cpufreq(unsigned int cpu)
{
if (!acpi_processor_cpufreq_init)
return 0;
struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
return policy != NULL; //Personally I find !! on a pointer a bit weird :)
}
> >
> > if (!acpi_processor_cpufreq_init)
> > return 0;
> >
> > - policy = cpufreq_cpu_get(cpu);
> > - if (policy) {
> > - cpufreq_cpu_put(policy);
> > - return 1;
> > - }
> > - return 0;
> > + return !!policy;
> > }
> >
> > static int cpufreq_get_max_state(unsigned int cpu)
> > @@ -93,9 +88,23 @@ static int cpufreq_get_cur_state(unsigned int cpu)
> > return reduction_step(cpu);
> > }
> >
> > +static long long cpufreq_get_max_freq(unsigned int cpu)
> > +{
> > + long long max_freq;
> > + struct cpufreq_policy *policy __free(put_cpufreq_policy) =
> > + cpufreq_cpu_get(cpu);
Format consistently. If you are going to wrap to 80 chars here
then do it for the cpu_has_cpufreq() line that is identical to this.
> > +
> > + if (!policy)
> > + return -EINVAL;
> > +
> > + max_freq = (policy->cpuinfo.max_freq *
> > + (100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100;
> > +
> > + return max_freq;
> > +}
> > +
> > 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;
> > @@ -120,14 +129,10 @@ 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)
> > - return -EINVAL;
> > -
> > - max_freq = (policy->cpuinfo.max_freq *
> > - (100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100;
> > + max_freq = cpufreq_get_max_freq(cpu);
> >
> > - cpufreq_cpu_put(policy);
> > + if (max_freq == -EINVAL)
> > + return -EINVAL;
>
> Please also move the code below to the new function so it does not
> need to return a value.
>
> >
> > ret = freq_qos_update_request(&pr->thermal_req, max_freq);
> > if (ret < 0) {
> > --
>
More information about the Linuxppc-dev
mailing list