[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0izu1_xVe_pGeJiXZqEXLxg_o30NkEjMiwzDgeU4mOGmA@mail.gmail.com>
Date: Fri, 5 Sep 2025 21:46:43 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Zihuan Zhang <zhangzihuan@...inos.cn>
Cc: "Rafael J . wysocki" <rafael@...nel.org>, Viresh Kumar <viresh.kumar@...aro.org>,
Jonathan Cameron <jonathan.cameron@...wei.com>, Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Srinivas Pandruvada <srinivas.pandruvada@...ux.intel.com>, Michael Ellerman <mpe@...erman.id.au>,
Krzysztof Kozlowski <krzk@...nel.org>, Alim Akhtar <alim.akhtar@...sung.com>,
Thierry Reding <thierry.reding@...il.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>, 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>, Ben Horgan <ben.horgan@....com>,
zhenglifeng <zhenglifeng1@...wei.com>, Zhang Rui <rui.zhang@...el.com>,
Len Brown <lenb@...nel.org>, 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,
linux-acpi@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
linux-arm-kernel@...ts.infradead.org, intel-gfx@...ts.freedesktop.org,
dri-devel@...ts.freedesktop.org, imx@...ts.linux.dev,
linux-omap@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5 6/6] PM: EM: Use scope-based cleanup helper
On Fri, Sep 5, 2025 at 3:25 PM 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>
> ---
> kernel/power/energy_model.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
> index ea7995a25780..5ec63b3e7d85 100644
> --- a/kernel/power/energy_model.c
> +++ b/kernel/power/energy_model.c
> @@ -451,7 +451,6 @@ static void
> em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
> {
> struct em_perf_domain *pd = dev->em_pd;
> - struct cpufreq_policy *policy;
> int found = 0;
> int i, cpu;
>
> @@ -465,7 +464,7 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
> return;
> }
>
> - policy = cpufreq_cpu_get(cpu);
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> if (!policy) {
> dev_warn(dev, "EM: Access to CPUFreq policy failed\n");
> return;
> @@ -479,8 +478,6 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
> found++;
> }
>
> - cpufreq_cpu_put(policy);
> -
> if (!found)
> return;
>
The above changes are fine now and can be a separate patch.
> @@ -787,21 +784,19 @@ static void em_check_capacity_update(void)
>
> /* Check if CPUs capacity has changed than update EM */
> for_each_possible_cpu(cpu) {
But I'd prefer the code in this loop to be moved into a separate
function, in a separate patch, before the __free()-based
simplification of it.
> - struct cpufreq_policy *policy;
> struct em_perf_domain *pd;
> struct device *dev;
>
> if (cpumask_test_cpu(cpu, cpu_done_mask))
> continue;
>
> - policy = cpufreq_cpu_get(cpu);
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> if (!policy) {
> pr_debug("Accessing cpu%d policy failed\n", cpu);
> schedule_delayed_work(&em_update_work,
> msecs_to_jiffies(1000));
> break;
> }
> - cpufreq_cpu_put(policy);
>
> dev = get_cpu_device(cpu);
> pd = em_pd_get(dev);
> --
Powered by blists - more mailing lists