mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zihuan Zhang <zhangzihuan@kylinos.cn>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
	Jonathan Cameron <jonathan.cameron@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	MyungJoo Ham <myungjoo.ham@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Jani Nikula <jani.nikula@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Tvrtko Ursulin <tursulin@ursulin.net>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Daniel Lezcano <daniel.lezcano@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Shawn Guo <shawnguo@kernel.org>,
	Eduardo Valentin <edubezval@gmail.com>,
	Keerthy <j-keerthy@ti.com>, Ben Horgan <ben.horgan@arm.com>,
	zhenglifeng <zhenglifeng1@huawei.com>,
	Zhang Rui <rui.zhang@intel.com>, Len Brown <lenb@kernel.org>,
	Lukasz Luba <lukasz.luba@arm.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Beata Michalska <beata.michalska@arm.com>,
	Fabio Estevam <festevam@gmail.com>,
	Pavel Machek <pavel@kernel.org>, Sumit Gupta <sumitg@nvidia.com>,
	Prasanna Kumar T S M <ptsm@linux.microsoft.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Yicong Yang <yangyicong@hisilicon.com>,
	linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org,
	linux-arm-kernel@lists.infradead.org,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	imx@lists.linux.dev, linux-omap@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/6] ACPI: processor: thermal: Use scope-based cleanup helper
Date: Mon, 8 Sep 2025 17:16:21 +0800	[thread overview]
Message-ID: <6683fb5a-64f4-433e-a22b-153b01dfa572@kylinos.cn> (raw)
In-Reply-To: <CAJZ5v0iTdgM5BBi2ysiJxfA2c=MQ0fjLsEvVct9stxomvEe=4Q@mail.gmail.com>


在 2025/9/6 04:17, Rafael J. Wysocki 写道:
> On Fri, Sep 5, 2025 at 3:24 PM Zihuan Zhang <zhangzihuan@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@kylinos.cn>
>> ---
>>   drivers/acpi/processor_thermal.c | 52 +++++++++++++++++---------------
>>   1 file changed, 27 insertions(+), 25 deletions(-)
>>
>> diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
>> index 1219adb11ab9..460713d1414a 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;
>> -
>>          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)
> The changes above are fine and can be sent as a separate patch.
>
>> @@ -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);
>> +       }
> But this silently fixes a bug in the original code which needs to be
> documented with a Fixes: tag (and it would be better to fix the bug
> separately before the using the __free()-based cleanup TBH) and
> introduces some whitespace breakage.

Thanks!

  I’ll follow your advice and handle the Fixes tag and whitespace issues.


>> +
>> +       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;
>>   }
>> --

  reply	other threads:[~2025-09-08  9:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 13:24 [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 1/6] arm64: topology: Use scope-based cleanup helper Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 2/6] ACPI: processor: thermal: " Zihuan Zhang
2025-09-05 20:17   ` Rafael J. Wysocki
2025-09-08  9:16     ` Zihuan Zhang [this message]
2025-09-08 17:44       ` Rafael J. Wysocki
2025-09-08 17:55   ` Rafael J. Wysocki
2025-09-05 13:24 ` [PATCH v5 3/6] cpufreq: intel_pstate: " Zihuan Zhang
2025-09-05 13:31   ` Rafael J. Wysocki
2025-09-05 13:24 ` [PATCH v5 4/6] PM / devfreq: " Zihuan Zhang
2025-09-05 19:39   ` Rafael J. Wysocki
2025-09-05 13:24 ` [PATCH v5 5/6] drm/i915: " Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 6/6] PM: EM: " Zihuan Zhang
2025-09-05 19:46   ` Rafael J. Wysocki
2025-09-05 17:49 ` [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Borislav Petkov
2025-09-08  9:12   ` Zihuan Zhang
2025-09-08  9:24     ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6683fb5a-64f4-433e-a22b-153b01dfa572@kylinos.cn \
    --to=zhangzihuan@kylinos.cn \
    --cc=airlied@gmail.com \
    --cc=alim.akhtar@samsung.com \
    --cc=beata.michalska@arm.com \
    --cc=ben.horgan@arm.com \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=cw00.choi@samsung.com \
    --cc=daniel.lezcano@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=edubezval@gmail.com \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=j-keerthy@ti.com \
    --cc=jani.nikula@linux.intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=kernel@pengutronix.de \
    --cc=krzk@kernel.org \
    --cc=kyungmin.park@samsung.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lukasz.luba@arm.com \
    --cc=mpe@ellerman.id.au \
    --cc=myungjoo.ham@samsung.com \
    --cc=pavel@kernel.org \
    --cc=ptsm@linux.microsoft.com \
    --cc=rafael@kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=rui.zhang@intel.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=sudeep.holla@arm.com \
    --cc=sumitg@nvidia.com \
    --cc=thierry.reding@gmail.com \
    --cc=tursulin@ursulin.net \
    --cc=viresh.kumar@linaro.org \
    --cc=will@kernel.org \
    --cc=yangyicong@hisilicon.com \
    --cc=zhenglifeng1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®