linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references
@ 2025-08-27  2:31 Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference Zihuan Zhang
                   ` (18 more replies)
  0 siblings, 19 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

This patchset converts all remaining cpufreq users to rely on the
__free(put_cpufreq_policy) annotation for policy references, instead of
calling cpufreq_cpu_put() manually.

Motivation:
- Reduce the chance of reference counting mistakes
- Make the code more consistent with the latest kernel style
- behavior remains the same, but reference counting is now safer 
  and easier to maintain.

The changes are split into 18 patches as they touch different subsystems
and are maintained by different people. There is no functional change.

V2:
 - Fix compile error in powernv-cpufreq.c
 - Split patch to separate logical changes

Zihuan Zhang (18):
  arm64: topology: Use __free(put_cpufreq_policy) for policy reference
  KVM: x86: Use __free(put_cpufreq_policy) for policy reference
  ACPI: processor: thermal: Use __free(put_cpufreq_policy) for policy
    reference
  cpufreq: brcmstb-avs-cpufreq: Use __free(put_cpufreq_policy) for
    policy reference
  cpufreq: CPPC: Use __free(put_cpufreq_policy) for policy reference
  cpufreq: intel_pstate: Use __free(put_cpufreq_policy) for policy
    reference
  cpufreq: longhaul: Use __free(put_cpufreq_policy) for policy reference
  cpufreq: mediatek: Use __free(put_cpufreq_policy) for policy reference
  cpufreq: powernv: Use __free(put_cpufreq_policy) for policy reference
  cpufreq: s5pv210: Use __free(put_cpufreq_policy) for policy reference
  cpufreq: tegra186: Use __free(put_cpufreq_policy) for policy reference
  PM / devfreq: Use __free(put_cpufreq_policy) for policy reference
  drm/i915: Use __free(put_cpufreq_policy) for policy reference
  cpufreq: powerpc: macintosh: Use __free(put_cpufreq_policy) for policy
    reference
  powercap: dtpm_cpu: Use __free(put_cpufreq_policy) for policy
    reference
  thermal: imx: Use __free(put_cpufreq_policy) for policy reference
  thermal/drivers/ti-soc-thermal:  Use __free(put_cpufreq_policy) for
    policy reference
  PM: EM: Use __free(put_cpufreq_policy) for policy reference

 arch/arm64/kernel/topology.c                  |  9 +++----
 arch/x86/kvm/x86.c                            | 10 ++++----
 drivers/acpi/processor_thermal.c              | 12 +++-------
 drivers/cpufreq/brcmstb-avs-cpufreq.c         |  4 +---
 drivers/cpufreq/cppc_cpufreq.c                |  4 +---
 drivers/cpufreq/intel_pstate.c                |  3 +--
 drivers/cpufreq/longhaul.c                    |  3 +--
 drivers/cpufreq/mediatek-cpufreq.c            |  6 ++---
 drivers/cpufreq/powernv-cpufreq.c             |  7 +++---
 drivers/cpufreq/s5pv210-cpufreq.c             |  3 +--
 drivers/cpufreq/tegra186-cpufreq.c            |  3 +--
 drivers/devfreq/governor_passive.c            | 19 ++++-----------
 drivers/gpu/drm/i915/gt/intel_llc.c           |  3 +--
 drivers/macintosh/windfarm_cpufreq_clamp.c    |  4 +---
 drivers/powercap/dtpm_cpu.c                   | 24 ++++++-------------
 drivers/thermal/imx_thermal.c                 | 13 ++++------
 .../ti-soc-thermal/ti-thermal-common.c        | 12 ++++------
 kernel/power/energy_model.c                   |  7 ++----
 18 files changed, 46 insertions(+), 100 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-27  8:30   ` Ben Horgan
  2025-08-27  2:31 ` [PATCH v2 02/18] KVM: x86: " Zihuan Zhang
                   ` (17 subsequent siblings)
  18 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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>
---
 arch/arm64/kernel/topology.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index 5d07ee85bdae..e3cb6d54f35b 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -307,17 +307,16 @@ int arch_freq_get_on_cpu(int cpu)
 		 */
 		if (!housekeeping_cpu(cpu, HK_TYPE_TICK) ||
 		    time_is_before_jiffies(last_update + msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) {
-			struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
+			struct cpufreq_policy *policy __free(put_cpufreq_policy);
 			int ref_cpu;
 
+			policy = cpufreq_cpu_get(cpu);
 			if (!policy)
 				return -EINVAL;
 
 			if (!cpumask_intersects(policy->related_cpus,
-						housekeeping_cpumask(HK_TYPE_TICK))) {
-				cpufreq_cpu_put(policy);
+						housekeeping_cpumask(HK_TYPE_TICK)))
 				return -EOPNOTSUPP;
-			}
 
 			for_each_cpu_wrap(ref_cpu, policy->cpus, cpu + 1) {
 				if (ref_cpu == start_cpu) {
@@ -329,8 +328,6 @@ int arch_freq_get_on_cpu(int cpu)
 					break;
 			}
 
-			cpufreq_cpu_put(policy);
-
 			if (ref_cpu >= nr_cpu_ids)
 				/* No alternative to pull info from */
 				return -EAGAIN;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 02/18] KVM: x86: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-27 14:13   ` Sean Christopherson
  2025-08-27  2:31 ` [PATCH v2 03/18] ACPI: processor: thermal: " Zihuan Zhang
                   ` (16 subsequent siblings)
  18 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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>
---
 arch/x86/kvm/x86.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a1c49bc681c4..2a825f4ec701 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9492,16 +9492,14 @@ static void kvm_timer_init(void)
 		max_tsc_khz = tsc_khz;
 
 		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
-			struct cpufreq_policy *policy;
+			struct cpufreq_policy *policy __free(put_cpufreq_policy);
 			int cpu;
 
 			cpu = get_cpu();
 			policy = cpufreq_cpu_get(cpu);
-			if (policy) {
-				if (policy->cpuinfo.max_freq)
-					max_tsc_khz = policy->cpuinfo.max_freq;
-				cpufreq_cpu_put(policy);
-			}
+			if (policy && policy->cpuinfo.max_freq)
+				max_tsc_khz = policy->cpuinfo.max_freq;
+
 			put_cpu();
 		}
 		cpufreq_register_notifier(&kvmclock_cpufreq_notifier_block,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 03/18] ACPI: processor: thermal: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 02/18] KVM: x86: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-28  9:40   ` Rafael J. Wysocki
  2025-08-27  2:31 ` [PATCH v2 04/18] cpufreq: brcmstb-avs-cpufreq: " Zihuan Zhang
                   ` (15 subsequent siblings)
  18 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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 | 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;
 }
 
 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);
 	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",
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 04/18] cpufreq: brcmstb-avs-cpufreq: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (2 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 03/18] ACPI: processor: thermal: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-29  5:59   ` Viresh Kumar
  2025-08-27  2:31 ` [PATCH v2 05/18] cpufreq: CPPC: " Zihuan Zhang
                   ` (14 subsequent siblings)
  18 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/cpufreq/brcmstb-avs-cpufreq.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
index 5940d262374f..71450cca8e9f 100644
--- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
+++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
@@ -480,7 +480,7 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv)
 
 static unsigned int brcm_avs_cpufreq_get(unsigned int cpu)
 {
-	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
+	struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
 	struct private_data *priv;
 
 	if (!policy)
@@ -488,8 +488,6 @@ static unsigned int brcm_avs_cpufreq_get(unsigned int cpu)
 
 	priv = policy->driver_data;
 
-	cpufreq_cpu_put(policy);
-
 	return brcm_avs_get_frequency(priv->base);
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 05/18] cpufreq: CPPC: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (3 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 04/18] cpufreq: brcmstb-avs-cpufreq: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-29  6:04   ` Viresh Kumar
  2025-08-27  2:31 ` [PATCH v2 06/18] cpufreq: intel_pstate: " Zihuan Zhang
                   ` (13 subsequent siblings)
  18 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/cpufreq/cppc_cpufreq.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index 4a17162a392d..7183754b1f31 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -726,7 +726,7 @@ static int cppc_get_perf_ctrs_sample(int cpu,
 static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)
 {
 	struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0};
-	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
+	struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
 	struct cppc_cpudata *cpu_data;
 	u64 delivered_perf;
 	int ret;
@@ -736,8 +736,6 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)
 
 	cpu_data = policy->driver_data;
 
-	cpufreq_cpu_put(policy);
-
 	ret = cppc_get_perf_ctrs_sample(cpu, &fb_ctrs_t0, &fb_ctrs_t1);
 	if (ret) {
 		if (ret == -EFAULT)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 06/18] cpufreq: intel_pstate: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (4 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 05/18] cpufreq: CPPC: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 07/18] cpufreq: longhaul: " Zihuan Zhang
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/cpufreq/intel_pstate.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index f366d35c5840..4e7e2990e9a6 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -1698,19 +1698,18 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
 static void update_qos_request(enum freq_qos_req_type type)
 {
 	struct freq_qos_request *req;
-	struct cpufreq_policy *policy;
 	int i;
 
 	for_each_possible_cpu(i) {
 		struct cpudata *cpu = all_cpu_data[i];
 		unsigned int freq, perf_pct;
+		struct cpufreq_policy *policy __free(put_cpufreq_policy);
 
 		policy = cpufreq_cpu_get(i);
 		if (!policy)
 			continue;
 
 		req = policy->driver_data;
-		cpufreq_cpu_put(policy);
 
 		if (!req)
 			continue;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 07/18] cpufreq: longhaul: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (5 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 06/18] cpufreq: intel_pstate: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 08/18] cpufreq: mediatek: " Zihuan Zhang
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/cpufreq/longhaul.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index ba0e08c8486a..ae5596919671 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -950,7 +950,7 @@ static int __init longhaul_init(void)
 
 static void __exit longhaul_exit(void)
 {
-	struct cpufreq_policy *policy = cpufreq_cpu_get(0);
+	struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(0);
 	int i;
 
 	for (i = 0; i < numscales; i++) {
@@ -968,7 +968,6 @@ static void __exit longhaul_exit(void)
 		}
 	}
 
-	cpufreq_cpu_put(policy);
 	cpufreq_unregister_driver(&longhaul_driver);
 	kfree(longhaul_table);
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 08/18] cpufreq: mediatek: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (6 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 07/18] cpufreq: longhaul: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-29  6:18   ` Viresh Kumar
  2025-08-27  2:31 ` [PATCH v2 09/18] cpufreq: powernv: " Zihuan Zhang
                   ` (10 subsequent siblings)
  18 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/cpufreq/mediatek-cpufreq.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index f3f02c4b6888..1fae060e16d9 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -320,7 +320,7 @@ static int mtk_cpufreq_opp_notifier(struct notifier_block *nb,
 	struct dev_pm_opp *new_opp;
 	struct mtk_cpu_dvfs_info *info;
 	unsigned long freq, volt;
-	struct cpufreq_policy *policy;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 	int ret = 0;
 
 	info = container_of(nb, struct mtk_cpu_dvfs_info, opp_nb);
@@ -354,11 +354,9 @@ static int mtk_cpufreq_opp_notifier(struct notifier_block *nb,
 
 			dev_pm_opp_put(new_opp);
 			policy = cpufreq_cpu_get(info->opp_cpu);
-			if (policy) {
+			if (policy)
 				cpufreq_driver_target(policy, freq / 1000,
 						      CPUFREQ_RELATION_L);
-				cpufreq_cpu_put(policy);
-			}
 		}
 	}
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 09/18] cpufreq: powernv: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (7 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 08/18] cpufreq: mediatek: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 10/18] cpufreq: s5pv210: " Zihuan Zhang
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/cpufreq/powernv-cpufreq.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index 7d9a5f656de8..782cf5a482c0 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -892,15 +892,15 @@ static int powernv_cpufreq_reboot_notifier(struct notifier_block *nb,
 				unsigned long action, void *unused)
 {
 	int cpu;
-	struct cpufreq_policy *cpu_policy;
 
 	rebooting = true;
 	for_each_online_cpu(cpu) {
+		struct cpufreq_policy *cpu_policy __free(put_cpufreq_policy);
+
 		cpu_policy = cpufreq_cpu_get(cpu);
 		if (!cpu_policy)
 			continue;
 		powernv_cpufreq_target_index(cpu_policy, get_nominal_index());
-		cpufreq_cpu_put(cpu_policy);
 	}
 
 	return NOTIFY_DONE;
@@ -913,7 +913,6 @@ static struct notifier_block powernv_cpufreq_reboot_nb = {
 static void powernv_cpufreq_work_fn(struct work_struct *work)
 {
 	struct chip *chip = container_of(work, struct chip, throttle);
-	struct cpufreq_policy *policy;
 	unsigned int cpu;
 	cpumask_t mask;
 
@@ -928,6 +927,7 @@ static void powernv_cpufreq_work_fn(struct work_struct *work)
 	chip->restore = false;
 	for_each_cpu(cpu, &mask) {
 		int index;
+		struct cpufreq_policy *policy __free(put_cpufreq_policy);
 
 		policy = cpufreq_cpu_get(cpu);
 		if (!policy)
@@ -935,7 +935,6 @@ static void powernv_cpufreq_work_fn(struct work_struct *work)
 		index = cpufreq_table_find_index_c(policy, policy->cur, false);
 		powernv_cpufreq_target_index(policy, index);
 		cpumask_andnot(&mask, &mask, policy->cpus);
-		cpufreq_cpu_put(policy);
 	}
 out:
 	cpus_read_unlock();
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 10/18] cpufreq: s5pv210: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (8 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 09/18] cpufreq: powernv: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-29  6:13   ` Viresh Kumar
  2025-08-27  2:31 ` [PATCH v2 11/18] cpufreq: tegra186: " Zihuan Zhang
                   ` (8 subsequent siblings)
  18 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/cpufreq/s5pv210-cpufreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
index 76c888ed8d16..95f1568e9530 100644
--- a/drivers/cpufreq/s5pv210-cpufreq.c
+++ b/drivers/cpufreq/s5pv210-cpufreq.c
@@ -555,7 +555,7 @@ static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this,
 						 unsigned long event, void *ptr)
 {
 	int ret;
-	struct cpufreq_policy *policy;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 
 	policy = cpufreq_cpu_get(0);
 	if (!policy) {
@@ -564,7 +564,6 @@ static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this,
 	}
 
 	ret = cpufreq_driver_target(policy, SLEEP_FREQ, 0);
-	cpufreq_cpu_put(policy);
 
 	if (ret < 0)
 		return NOTIFY_BAD;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 11/18] cpufreq: tegra186: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (9 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 10/18] cpufreq: s5pv210: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-29  6:29   ` Viresh Kumar
  2025-08-27  2:31 ` [PATCH v2 12/18] PM / devfreq: " Zihuan Zhang
                   ` (7 subsequent siblings)
  18 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/cpufreq/tegra186-cpufreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cpufreq/tegra186-cpufreq.c b/drivers/cpufreq/tegra186-cpufreq.c
index cbabb726c664..4d71e262a729 100644
--- a/drivers/cpufreq/tegra186-cpufreq.c
+++ b/drivers/cpufreq/tegra186-cpufreq.c
@@ -105,7 +105,7 @@ static unsigned int tegra186_cpufreq_get(unsigned int cpu)
 {
 	struct tegra186_cpufreq_data *data = cpufreq_get_driver_data();
 	struct tegra186_cpufreq_cluster *cluster;
-	struct cpufreq_policy *policy;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 	unsigned int edvd_offset, cluster_id;
 	u32 ndiv;
 
@@ -117,7 +117,6 @@ static unsigned int tegra186_cpufreq_get(unsigned int cpu)
 	ndiv = readl(data->regs + edvd_offset) & EDVD_CORE_VOLT_FREQ_F_MASK;
 	cluster_id = data->cpus[policy->cpu].bpmp_cluster_id;
 	cluster = &data->clusters[cluster_id];
-	cpufreq_cpu_put(policy);
 
 	return (cluster->ref_clk_khz * ndiv) / cluster->div;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 12/18] PM / devfreq: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (10 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 11/18] cpufreq: tegra186: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 13/18] drm/i915: " Zihuan Zhang
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/devfreq/governor_passive.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c
index 953cf9a1e9f7..99597c921e38 100644
--- a/drivers/devfreq/governor_passive.c
+++ b/drivers/devfreq/governor_passive.c
@@ -80,13 +80,13 @@ static int get_target_freq_with_cpufreq(struct devfreq *devfreq,
 	struct devfreq_passive_data *p_data =
 				(struct devfreq_passive_data *)devfreq->data;
 	struct devfreq_cpu_data *parent_cpu_data;
-	struct cpufreq_policy *policy;
 	unsigned long cpu, cpu_cur, cpu_min, cpu_max, cpu_percent;
 	unsigned long dev_min, dev_max;
 	unsigned long freq = 0;
 	int ret = 0;
 
 	for_each_online_cpu(cpu) {
+		struct cpufreq_policy *policy __free(put_cpufreq_policy);
 		policy = cpufreq_cpu_get(cpu);
 		if (!policy) {
 			ret = -EINVAL;
@@ -94,10 +94,8 @@ static int get_target_freq_with_cpufreq(struct devfreq *devfreq,
 		}
 
 		parent_cpu_data = get_parent_cpu_data(p_data, policy);
-		if (!parent_cpu_data) {
-			cpufreq_cpu_put(policy);
+		if (!parent_cpu_data)
 			continue;
-		}
 
 		/* Get target freq via required opps */
 		cpu_cur = parent_cpu_data->cur_freq * HZ_PER_KHZ;
@@ -106,7 +104,6 @@ static int get_target_freq_with_cpufreq(struct devfreq *devfreq,
 					devfreq->opp_table, &cpu_cur);
 		if (freq) {
 			*target_freq = max(freq, *target_freq);
-			cpufreq_cpu_put(policy);
 			continue;
 		}
 
@@ -121,7 +118,6 @@ static int get_target_freq_with_cpufreq(struct devfreq *devfreq,
 		freq = dev_min + mult_frac(dev_max - dev_min, cpu_percent, 100);
 
 		*target_freq = max(freq, *target_freq);
-		cpufreq_cpu_put(policy);
 	}
 
 	return ret;
@@ -256,7 +252,6 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
 	struct device *dev = devfreq->dev.parent;
 	struct opp_table *opp_table = NULL;
 	struct devfreq_cpu_data *parent_cpu_data;
-	struct cpufreq_policy *policy;
 	struct device *cpu_dev;
 	unsigned int cpu;
 	int ret;
@@ -273,6 +268,7 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
 	}
 
 	for_each_possible_cpu(cpu) {
+		struct cpufreq_policy *policy __free(put_cpufreq_policy);
 		policy = cpufreq_cpu_get(cpu);
 		if (!policy) {
 			ret = -EPROBE_DEFER;
@@ -280,16 +276,14 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
 		}
 
 		parent_cpu_data = get_parent_cpu_data(p_data, policy);
-		if (parent_cpu_data) {
-			cpufreq_cpu_put(policy);
+		if (parent_cpu_data)
 			continue;
-		}
 
 		parent_cpu_data = kzalloc(sizeof(*parent_cpu_data),
 						GFP_KERNEL);
 		if (!parent_cpu_data) {
 			ret = -ENOMEM;
-			goto err_put_policy;
+			goto err;
 		}
 
 		cpu_dev = get_cpu_device(cpu);
@@ -314,7 +308,6 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
 		parent_cpu_data->max_freq = policy->cpuinfo.max_freq;
 
 		list_add_tail(&parent_cpu_data->node, &p_data->cpu_data_list);
-		cpufreq_cpu_put(policy);
 	}
 
 	mutex_lock(&devfreq->lock);
@@ -327,8 +320,6 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
 
 err_free_cpu_data:
 	kfree(parent_cpu_data);
-err_put_policy:
-	cpufreq_cpu_put(policy);
 err:
 
 	return ret;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 13/18] drm/i915: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (11 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 12/18] PM / devfreq: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 14/18] cpufreq: powerpc: macintosh: " Zihuan Zhang
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/gpu/drm/i915/gt/intel_llc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/intel_llc.c b/drivers/gpu/drm/i915/gt/intel_llc.c
index 1d19c073ba2e..53cef2ab133d 100644
--- a/drivers/gpu/drm/i915/gt/intel_llc.c
+++ b/drivers/gpu/drm/i915/gt/intel_llc.c
@@ -29,13 +29,12 @@ static struct intel_gt *llc_to_gt(struct intel_llc *llc)
 
 static unsigned int cpu_max_MHz(void)
 {
-	struct cpufreq_policy *policy;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 	unsigned int max_khz;
 
 	policy = cpufreq_cpu_get(0);
 	if (policy) {
 		max_khz = policy->cpuinfo.max_freq;
-		cpufreq_cpu_put(policy);
 	} else {
 		/*
 		 * Default to measured freq if none found, PCU will ensure we
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 14/18] cpufreq: powerpc: macintosh: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (12 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 13/18] drm/i915: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-27  2:31 ` [PATCH v2 15/18] powercap: dtpm_cpu: " Zihuan Zhang
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/macintosh/windfarm_cpufreq_clamp.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/macintosh/windfarm_cpufreq_clamp.c b/drivers/macintosh/windfarm_cpufreq_clamp.c
index 28d18ef22bbb..f05e2167481f 100644
--- a/drivers/macintosh/windfarm_cpufreq_clamp.c
+++ b/drivers/macintosh/windfarm_cpufreq_clamp.c
@@ -62,7 +62,7 @@ static const struct wf_control_ops clamp_ops = {
 
 static int __init wf_cpufreq_clamp_init(void)
 {
-	struct cpufreq_policy *policy;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 	struct wf_control *clamp;
 	struct device *dev;
 	int ret;
@@ -79,8 +79,6 @@ static int __init wf_cpufreq_clamp_init(void)
 	ret = freq_qos_add_request(&policy->constraints, &qos_req, FREQ_QOS_MAX,
 				   max_freq);
 
-	cpufreq_cpu_put(policy);
-
 	if (ret < 0) {
 		pr_err("%s: Failed to add freq constraint (%d)\n", __func__,
 		       ret);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 15/18] powercap: dtpm_cpu: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (13 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 14/18] cpufreq: powerpc: macintosh: " Zihuan Zhang
@ 2025-08-27  2:31 ` Zihuan Zhang
  2025-08-27  2:32 ` [PATCH v2 16/18] thermal: imx: " Zihuan Zhang
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:31 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/powercap/dtpm_cpu.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c
index 99390ec1481f..65117569d0f3 100644
--- a/drivers/powercap/dtpm_cpu.c
+++ b/drivers/powercap/dtpm_cpu.c
@@ -144,19 +144,16 @@ static int update_pd_power_uw(struct dtpm *dtpm)
 static void pd_release(struct dtpm *dtpm)
 {
 	struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm);
-	struct cpufreq_policy *policy;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 
 	if (freq_qos_request_active(&dtpm_cpu->qos_req))
 		freq_qos_remove_request(&dtpm_cpu->qos_req);
 
 	policy = cpufreq_cpu_get(dtpm_cpu->cpu);
-	if (policy) {
+	if (policy)
 		for_each_cpu(dtpm_cpu->cpu, policy->related_cpus)
 			per_cpu(dtpm_per_cpu, dtpm_cpu->cpu) = NULL;
 
-		cpufreq_cpu_put(policy);
-	}
-
 	kfree(dtpm_cpu);
 }
 
@@ -192,7 +189,7 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu)
 static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 {
 	struct dtpm_cpu *dtpm_cpu;
-	struct cpufreq_policy *policy;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 	struct em_perf_state *table;
 	struct em_perf_domain *pd;
 	char name[CPUFREQ_NAME_LEN];
@@ -207,16 +204,12 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 		return 0;
 
 	pd = em_cpu_get(cpu);
-	if (!pd || em_is_artificial(pd)) {
-		ret = -EINVAL;
-		goto release_policy;
-	}
+	if (!pd || em_is_artificial(pd))
+		return -EINVAL;
 
 	dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL);
-	if (!dtpm_cpu) {
-		ret = -ENOMEM;
-		goto release_policy;
-	}
+	if (!dtpm_cpu)
+		return -ENOMEM;
 
 	dtpm_init(&dtpm_cpu->dtpm, &dtpm_ops);
 	dtpm_cpu->cpu = cpu;
@@ -239,7 +232,6 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 	if (ret < 0)
 		goto out_dtpm_unregister;
 
-	cpufreq_cpu_put(policy);
 	return 0;
 
 out_dtpm_unregister:
@@ -251,8 +243,6 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 		per_cpu(dtpm_per_cpu, cpu) = NULL;
 	kfree(dtpm_cpu);
 
-release_policy:
-	cpufreq_cpu_put(policy);
 	return ret;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 16/18] thermal: imx: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (14 preceding siblings ...)
  2025-08-27  2:31 ` [PATCH v2 15/18] powercap: dtpm_cpu: " Zihuan Zhang
@ 2025-08-27  2:32 ` Zihuan Zhang
  2025-08-27  2:32 ` [PATCH v2 17/18] thermal/drivers/ti-soc-thermal: " Zihuan Zhang
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:32 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/thermal/imx_thermal.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index 38c993d1bcb3..8e776d314d88 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -201,7 +201,6 @@ static struct thermal_soc_data thermal_imx7d_data = {
 
 struct imx_thermal_data {
 	struct device *dev;
-	struct cpufreq_policy *policy;
 	struct thermal_zone_device *tz;
 	struct thermal_cooling_device *cdev;
 	struct regmap *tempmon;
@@ -541,22 +540,21 @@ MODULE_DEVICE_TABLE(of, of_imx_thermal_match);
 static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
 {
 	struct device_node *np;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 	int ret = 0;
 
-	data->policy = cpufreq_cpu_get(0);
-	if (!data->policy) {
+	policy = cpufreq_cpu_get(0);
+	if (!policy) {
 		pr_debug("%s: CPUFreq policy not found\n", __func__);
 		return -EPROBE_DEFER;
 	}
 
-	np = of_get_cpu_node(data->policy->cpu, NULL);
+	np = of_get_cpu_node(policy->cpu, NULL);
 
 	if (!np || !of_property_present(np, "#cooling-cells")) {
 		data->cdev = cpufreq_cooling_register(data->policy);
-		if (IS_ERR(data->cdev)) {
+		if (IS_ERR(data->cdev))
 			ret = PTR_ERR(data->cdev);
-			cpufreq_cpu_put(data->policy);
-		}
 	}
 
 	of_node_put(np);
@@ -567,7 +565,6 @@ static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
 static void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data *data)
 {
 	cpufreq_cooling_unregister(data->cdev);
-	cpufreq_cpu_put(data->policy);
 }
 
 #else
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 17/18] thermal/drivers/ti-soc-thermal:  Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (15 preceding siblings ...)
  2025-08-27  2:32 ` [PATCH v2 16/18] thermal: imx: " Zihuan Zhang
@ 2025-08-27  2:32 ` Zihuan Zhang
  2025-08-27  2:32 ` [PATCH v2 18/18] PM: EM: " Zihuan Zhang
  2025-08-27  3:50 ` [PATCH v2 15/18] powercap: dtpm_cpu: " Zihuan Zhang
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:32 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/thermal/ti-soc-thermal/ti-thermal-common.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
index 0cf0826b805a..c0db27670974 100644
--- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
@@ -27,7 +27,6 @@
 
 /* common data structures */
 struct ti_thermal_data {
-	struct cpufreq_policy *policy;
 	struct thermal_zone_device *ti_thermal;
 	struct thermal_zone_device *pcb_tz;
 	struct thermal_cooling_device *cool_dev;
@@ -218,6 +217,7 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
 {
 	struct ti_thermal_data *data;
 	struct device_node *np = bgp->dev->of_node;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 
 	/*
 	 * We are assuming here that if one deploys the zone
@@ -234,8 +234,8 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
 	if (!data)
 		return -EINVAL;
 
-	data->policy = cpufreq_cpu_get(0);
-	if (!data->policy) {
+	policy = cpufreq_cpu_get(0);
+	if (!policy) {
 		pr_debug("%s: CPUFreq policy not found\n", __func__);
 		return -EPROBE_DEFER;
 	}
@@ -246,7 +246,6 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id)
 		int ret = PTR_ERR(data->cool_dev);
 		dev_err(bgp->dev, "Failed to register cpu cooling device %d\n",
 			ret);
-		cpufreq_cpu_put(data->policy);
 
 		return ret;
 	}
@@ -261,11 +260,8 @@ int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id)
 
 	data = ti_bandgap_get_sensor_data(bgp, id);
 
-	if (!IS_ERR_OR_NULL(data)) {
+	if (!IS_ERR_OR_NULL(data))
 		cpufreq_cooling_unregister(data->cool_dev);
-		if (data->policy)
-			cpufreq_cpu_put(data->policy);
-	}
 
 	return 0;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 18/18] PM: EM: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (16 preceding siblings ...)
  2025-08-27  2:32 ` [PATCH v2 17/18] thermal/drivers/ti-soc-thermal: " Zihuan Zhang
@ 2025-08-27  2:32 ` Zihuan Zhang
  2025-08-27  3:50 ` [PATCH v2 15/18] powercap: dtpm_cpu: " Zihuan Zhang
  18 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  2:32 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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>
---
 kernel/power/energy_model.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
index ea7995a25780..4f91112c10bd 100644
--- a/kernel/power/energy_model.c
+++ b/kernel/power/energy_model.c
@@ -451,7 +451,7 @@ 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;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 	int found = 0;
 	int i, cpu;
 
@@ -479,8 +479,6 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
 			found++;
 	}
 
-	cpufreq_cpu_put(policy);
-
 	if (!found)
 		return;
 
@@ -787,7 +785,7 @@ static void em_check_capacity_update(void)
 
 	/* Check if CPUs capacity has changed than update EM */
 	for_each_possible_cpu(cpu) {
-		struct cpufreq_policy *policy;
+		struct cpufreq_policy *policy __free(put_cpufreq_policy);
 		struct em_perf_domain *pd;
 		struct device *dev;
 
@@ -801,7 +799,6 @@ static void em_check_capacity_update(void)
 					      msecs_to_jiffies(1000));
 			break;
 		}
-		cpufreq_cpu_put(policy);
 
 		dev = get_cpu_device(cpu);
 		pd = em_pd_get(dev);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH v2 15/18] powercap: dtpm_cpu: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
                   ` (17 preceding siblings ...)
  2025-08-27  2:32 ` [PATCH v2 18/18] PM: EM: " Zihuan Zhang
@ 2025-08-27  3:50 ` Zihuan Zhang
  2025-08-27  5:21   ` Zihuan Zhang
  18 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  3:50 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel,
	Zihuan Zhang

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/powercap/dtpm_cpu.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c
index 99390ec1481f..65117569d0f3 100644
--- a/drivers/powercap/dtpm_cpu.c
+++ b/drivers/powercap/dtpm_cpu.c
@@ -144,19 +144,16 @@ static int update_pd_power_uw(struct dtpm *dtpm)
 static void pd_release(struct dtpm *dtpm)
 {
 	struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm);
-	struct cpufreq_policy *policy;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 
 	if (freq_qos_request_active(&dtpm_cpu->qos_req))
 		freq_qos_remove_request(&dtpm_cpu->qos_req);
 
 	policy = cpufreq_cpu_get(dtpm_cpu->cpu);
-	if (policy) {
+	if (policy)
 		for_each_cpu(dtpm_cpu->cpu, policy->related_cpus)
 			per_cpu(dtpm_per_cpu, dtpm_cpu->cpu) = NULL;
 
-		cpufreq_cpu_put(policy);
-	}
-
 	kfree(dtpm_cpu);
 }
 
@@ -192,7 +189,7 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu)
 static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 {
 	struct dtpm_cpu *dtpm_cpu;
-	struct cpufreq_policy *policy;
+	struct cpufreq_policy *policy __free(put_cpufreq_policy);
 	struct em_perf_state *table;
 	struct em_perf_domain *pd;
 	char name[CPUFREQ_NAME_LEN];
@@ -207,16 +204,12 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 		return 0;
 
 	pd = em_cpu_get(cpu);
-	if (!pd || em_is_artificial(pd)) {
-		ret = -EINVAL;
-		goto release_policy;
-	}
+	if (!pd || em_is_artificial(pd))
+		return -EINVAL;
 
 	dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL);
-	if (!dtpm_cpu) {
-		ret = -ENOMEM;
-		goto release_policy;
-	}
+	if (!dtpm_cpu)
+		return -ENOMEM;
 
 	dtpm_init(&dtpm_cpu->dtpm, &dtpm_ops);
 	dtpm_cpu->cpu = cpu;
@@ -239,7 +232,6 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 	if (ret < 0)
 		goto out_dtpm_unregister;
 
-	cpufreq_cpu_put(policy);
 	return 0;
 
 out_dtpm_unregister:
@@ -251,8 +243,6 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
 		per_cpu(dtpm_per_cpu, cpu) = NULL;
 	kfree(dtpm_cpu);
 
-release_policy:
-	cpufreq_cpu_put(policy);
 	return ret;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 15/18] powercap: dtpm_cpu: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  3:50 ` [PATCH v2 15/18] powercap: dtpm_cpu: " Zihuan Zhang
@ 2025-08-27  5:21   ` Zihuan Zhang
  0 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  5:21 UTC (permalink / raw)
  To: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel

在 2025/8/27 11:50, Zihuan Zhang 写道:

> 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/powercap/dtpm_cpu.c | 24 +++++++-----------------
>   1 file changed, 7 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c
> index 99390ec1481f..65117569d0f3 100644
> --- a/drivers/powercap/dtpm_cpu.c
> +++ b/drivers/powercap/dtpm_cpu.c
> @@ -144,19 +144,16 @@ static int update_pd_power_uw(struct dtpm *dtpm)
>   static void pd_release(struct dtpm *dtpm)
>   {
>   	struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm);
> -	struct cpufreq_policy *policy;
> +	struct cpufreq_policy *policy __free(put_cpufreq_policy);
>   
>   	if (freq_qos_request_active(&dtpm_cpu->qos_req))
>   		freq_qos_remove_request(&dtpm_cpu->qos_req);
>   
>   	policy = cpufreq_cpu_get(dtpm_cpu->cpu);
> -	if (policy) {
> +	if (policy)
>   		for_each_cpu(dtpm_cpu->cpu, policy->related_cpus)
>   			per_cpu(dtpm_per_cpu, dtpm_cpu->cpu) = NULL;
>   
> -		cpufreq_cpu_put(policy);
> -	}
> -
>   	kfree(dtpm_cpu);
>   }
>   
> @@ -192,7 +189,7 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu)
>   static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
>   {
>   	struct dtpm_cpu *dtpm_cpu;
> -	struct cpufreq_policy *policy;
> +	struct cpufreq_policy *policy __free(put_cpufreq_policy);
>   	struct em_perf_state *table;
>   	struct em_perf_domain *pd;
>   	char name[CPUFREQ_NAME_LEN];
> @@ -207,16 +204,12 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
>   		return 0;
>   
>   	pd = em_cpu_get(cpu);
> -	if (!pd || em_is_artificial(pd)) {
> -		ret = -EINVAL;
> -		goto release_policy;
> -	}
> +	if (!pd || em_is_artificial(pd))
> +		return -EINVAL;
>   
>   	dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL);
> -	if (!dtpm_cpu) {
> -		ret = -ENOMEM;
> -		goto release_policy;
> -	}
> +	if (!dtpm_cpu)
> +		return -ENOMEM;
>   
>   	dtpm_init(&dtpm_cpu->dtpm, &dtpm_ops);
>   	dtpm_cpu->cpu = cpu;
> @@ -239,7 +232,6 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
>   	if (ret < 0)
>   		goto out_dtpm_unregister;
>   
> -	cpufreq_cpu_put(policy);
>   	return 0;
>   
>   out_dtpm_unregister:
> @@ -251,8 +243,6 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
>   		per_cpu(dtpm_per_cpu, cpu) = NULL;
>   	kfree(dtpm_cpu);
>   
> -release_policy:
> -	cpufreq_cpu_put(policy);
>   	return ret;
>   }
>   
I accidentally sent a duplicate patch in the series.
Please ignore the extra one, sorry for the noise.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 ` [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference Zihuan Zhang
@ 2025-08-27  8:30   ` Ben Horgan
  2025-08-27  8:55     ` Zihuan Zhang
                       ` (2 more replies)
  0 siblings, 3 replies; 40+ messages in thread
From: Ben Horgan @ 2025-08-27  8:30 UTC (permalink / raw)
  To: Zihuan Zhang, Rafael J . wysocki, Viresh Kumar, Catalin Marinas,
	Will Deacon, Sean Christopherson, Paolo Bonzini, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, Markus Mayer,
	Florian Fainelli, Srinivas Pandruvada, Madhavan Srinivasan,
	Michael Ellerman, Krzysztof Kozlowski, Alim Akhtar,
	Thierry Reding, Jonathan Hunter, MyungJoo Ham, Kyungmin Park,
	Chanwoo Choi, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Daniel Lezcano,
	Sascha Hauer, Shawn Guo, Eduardo Valentin, Keerthy,
	Matthias Brugger, AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel

Hi Zihuan,

On 8/27/25 03:31, Zihuan Zhang 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>
> ---
>  arch/arm64/kernel/topology.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> index 5d07ee85bdae..e3cb6d54f35b 100644
> --- a/arch/arm64/kernel/topology.c
> +++ b/arch/arm64/kernel/topology.c
> @@ -307,17 +307,16 @@ int arch_freq_get_on_cpu(int cpu)
>  		 */
>  		if (!housekeeping_cpu(cpu, HK_TYPE_TICK) ||
>  		    time_is_before_jiffies(last_update + msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) {
> -			struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
> +			struct cpufreq_policy *policy __free(put_cpufreq_policy);
Based on the guidance, in include/linux/cleanup.h, I would expect the
assignment to be done on this line.

"...the recommendation is to always define and assign variables in one
 * statement and not group variable definitions at the top of the
 * function when __free() is used."
>  			int ref_cpu;
>  
> +			policy = cpufreq_cpu_get(cpu);
>  			if (!policy)
>  				return -EINVAL;
>  
>  			if (!cpumask_intersects(policy->related_cpus,
> -						housekeeping_cpumask(HK_TYPE_TICK))) {
> -				cpufreq_cpu_put(policy);
> +						housekeeping_cpumask(HK_TYPE_TICK)))
>  				return -EOPNOTSUPP;
> -			}
>  
>  			for_each_cpu_wrap(ref_cpu, policy->cpus, cpu + 1) {
>  				if (ref_cpu == start_cpu) {
> @@ -329,8 +328,6 @@ int arch_freq_get_on_cpu(int cpu)
>  					break;
>  			}
>  
> -			cpufreq_cpu_put(policy);
> -
>  			if (ref_cpu >= nr_cpu_ids)
>  				/* No alternative to pull info from */
>  				return -EAGAIN;

Thanks,

Ben


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  8:30   ` Ben Horgan
@ 2025-08-27  8:55     ` Zihuan Zhang
  2025-08-27  9:12       ` Ben Horgan
  2025-08-27  9:17     ` Sudeep Holla
       [not found]     ` <1756341899099493.57.seg@mailgw.kylinos.cn>
  2 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  8:55 UTC (permalink / raw)
  To: Ben Horgan, Rafael J . wysocki, Viresh Kumar, Catalin Marinas,
	Will Deacon, Sean Christopherson, Paolo Bonzini, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, Markus Mayer,
	Florian Fainelli, Srinivas Pandruvada, Madhavan Srinivasan,
	Michael Ellerman, Krzysztof Kozlowski, Alim Akhtar,
	Thierry Reding, Jonathan Hunter, MyungJoo Ham, Kyungmin Park,
	Chanwoo Choi, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Daniel Lezcano,
	Sascha Hauer, Shawn Guo, Eduardo Valentin, Keerthy,
	Matthias Brugger, AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel

Hi,

在 2025/8/27 16:30, Ben Horgan 写道:
> Hi Zihuan,
>
> On 8/27/25 03:31, Zihuan Zhang 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>
>> ---
>>   arch/arm64/kernel/topology.c | 9 +++------
>>   1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
>> index 5d07ee85bdae..e3cb6d54f35b 100644
>> --- a/arch/arm64/kernel/topology.c
>> +++ b/arch/arm64/kernel/topology.c
>> @@ -307,17 +307,16 @@ int arch_freq_get_on_cpu(int cpu)
>>   		 */
>>   		if (!housekeeping_cpu(cpu, HK_TYPE_TICK) ||
>>   		    time_is_before_jiffies(last_update + msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) {
>> -			struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
>> +			struct cpufreq_policy *policy __free(put_cpufreq_policy);
> Based on the guidance, in include/linux/cleanup.h, I would expect the
> assignment to be done on this line.
>
> "...the recommendation is to always define and assign variables in one
>   * statement and not group variable definitions at the top of the
>   * function when __free() is used."


The reason I split the assignment into multiple lines is because 
scripts/checkpatch.pl gave a warning about the line being too long.

But if you think a single-line assignment is better, I will modify it 
accordingly.

>>   			int ref_cpu;
>>   
>> +			policy = cpufreq_cpu_get(cpu);
>>   			if (!policy)
>>   				return -EINVAL;
>>   
>>   			if (!cpumask_intersects(policy->related_cpus,
>> -						housekeeping_cpumask(HK_TYPE_TICK))) {
>> -				cpufreq_cpu_put(policy);
>> +						housekeeping_cpumask(HK_TYPE_TICK)))
>>   				return -EOPNOTSUPP;
>> -			}
>>   
>>   			for_each_cpu_wrap(ref_cpu, policy->cpus, cpu + 1) {
>>   				if (ref_cpu == start_cpu) {
>> @@ -329,8 +328,6 @@ int arch_freq_get_on_cpu(int cpu)
>>   					break;
>>   			}
>>   
>> -			cpufreq_cpu_put(policy);
>> -
>>   			if (ref_cpu >= nr_cpu_ids)
>>   				/* No alternative to pull info from */
>>   				return -EAGAIN;
> Thanks,
>
> Ben
>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  8:55     ` Zihuan Zhang
@ 2025-08-27  9:12       ` Ben Horgan
  2025-08-27  9:21         ` Zihuan Zhang
  0 siblings, 1 reply; 40+ messages in thread
From: Ben Horgan @ 2025-08-27  9:12 UTC (permalink / raw)
  To: Zihuan Zhang, Rafael J . wysocki, Viresh Kumar, Catalin Marinas,
	Will Deacon, Sean Christopherson, Paolo Bonzini, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, Markus Mayer,
	Florian Fainelli, Srinivas Pandruvada, Madhavan Srinivasan,
	Michael Ellerman, Krzysztof Kozlowski, Alim Akhtar,
	Thierry Reding, Jonathan Hunter, MyungJoo Ham, Kyungmin Park,
	Chanwoo Choi, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Daniel Lezcano,
	Sascha Hauer, Shawn Guo, Eduardo Valentin, Keerthy,
	Matthias Brugger, AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel

Hi Zihuan,

On 8/27/25 09:55, Zihuan Zhang wrote:
> Hi,
> 
> 在 2025/8/27 16:30, Ben Horgan 写道:
>> Hi Zihuan,
>>
>> On 8/27/25 03:31, Zihuan Zhang 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>
>>> ---
>>>   arch/arm64/kernel/topology.c | 9 +++------
>>>   1 file changed, 3 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
>>> index 5d07ee85bdae..e3cb6d54f35b 100644
>>> --- a/arch/arm64/kernel/topology.c
>>> +++ b/arch/arm64/kernel/topology.c
>>> @@ -307,17 +307,16 @@ int arch_freq_get_on_cpu(int cpu)
>>>            */
>>>           if (!housekeeping_cpu(cpu, HK_TYPE_TICK) ||
>>>               time_is_before_jiffies(last_update +
>>> msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) {
>>> -            struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
>>> +            struct cpufreq_policy *policy __free(put_cpufreq_policy);
>> Based on the guidance, in include/linux/cleanup.h, I would expect the
>> assignment to be done on this line.
>>
>> "...the recommendation is to always define and assign variables in one
>>   * statement and not group variable definitions at the top of the
>>   * function when __free() is used."
> 
> 
> The reason I split the assignment into multiple lines is because
> scripts/checkpatch.pl gave a warning about the line being too long.
> 
> But if you think a single-line assignment is better, I will modify it
> accordingly.

My preference, for what it's worth, would be to keep it one statement
and split the line after the =.

> 
>>>               int ref_cpu;
>>>   +            policy = cpufreq_cpu_get(cpu);
>>>               if (!policy)
>>>                   return -EINVAL;
>>>                 if (!cpumask_intersects(policy->related_cpus,
>>> -                        housekeeping_cpumask(HK_TYPE_TICK))) {
>>> -                cpufreq_cpu_put(policy);
>>> +                        housekeeping_cpumask(HK_TYPE_TICK)))
>>>                   return -EOPNOTSUPP;
>>> -            }
>>>                 for_each_cpu_wrap(ref_cpu, policy->cpus, cpu + 1) {
>>>                   if (ref_cpu == start_cpu) {
>>> @@ -329,8 +328,6 @@ int arch_freq_get_on_cpu(int cpu)
>>>                       break;
>>>               }
>>>   -            cpufreq_cpu_put(policy);
>>> -
>>>               if (ref_cpu >= nr_cpu_ids)
>>>                   /* No alternative to pull info from */
>>>                   return -EAGAIN;
>> Thanks,
>>
>> Ben
>>

Thanks,

Ben


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  8:30   ` Ben Horgan
  2025-08-27  8:55     ` Zihuan Zhang
@ 2025-08-27  9:17     ` Sudeep Holla
       [not found]     ` <1756341899099493.57.seg@mailgw.kylinos.cn>
  2 siblings, 0 replies; 40+ messages in thread
From: Sudeep Holla @ 2025-08-27  9:17 UTC (permalink / raw)
  To: Ben Horgan
  Cc: Zihuan Zhang, Sudeep Holla, Rafael J . wysocki, Viresh Kumar,
	Catalin Marinas, Will Deacon, Sean Christopherson, Paolo Bonzini,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	Markus Mayer, Florian Fainelli, Srinivas Pandruvada,
	Madhavan Srinivasan, Michael Ellerman, Krzysztof Kozlowski,
	Alim Akhtar, Thierry Reding, Jonathan Hunter, MyungJoo Ham,
	Kyungmin Park, Chanwoo Choi, Jani Nikula, Joonas Lahtinen,
	Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
	Daniel Lezcano, Sascha Hauer, Shawn Guo, Eduardo Valentin,
	Keerthy, Matthias Brugger, AngeloGioacchino Del Regno,
	zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Yicong Yang,
	linux-pm, x86, kvm, linux-acpi, linuxppc-dev, linux-samsung-soc,
	linux-arm-kernel, linux-tegra, intel-gfx, dri-devel, imx,
	linux-omap, linux-mediatek, linux-kernel

On Wed, Aug 27, 2025 at 09:30:13AM +0100, Ben Horgan wrote:
> Hi Zihuan,
> 
> On 8/27/25 03:31, Zihuan Zhang 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>
> > ---
> >  arch/arm64/kernel/topology.c | 9 +++------
> >  1 file changed, 3 insertions(+), 6 deletions(-)
> > 
> > diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
> > index 5d07ee85bdae..e3cb6d54f35b 100644
> > --- a/arch/arm64/kernel/topology.c
> > +++ b/arch/arm64/kernel/topology.c
> > @@ -307,17 +307,16 @@ int arch_freq_get_on_cpu(int cpu)
> >  		 */
> >  		if (!housekeeping_cpu(cpu, HK_TYPE_TICK) ||
> >  		    time_is_before_jiffies(last_update + msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) {
> > -			struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
> > +			struct cpufreq_policy *policy __free(put_cpufreq_policy);
> Based on the guidance, in include/linux/cleanup.h, I would expect the
> assignment to be done on this line.
> 
> "...the recommendation is to always define and assign variables in one
>  * statement and not group variable definitions at the top of the
>  * function when __free() is used."
> 

Agreed. I did something similar recently and there was a code path where
variable wasn't initialised and ended up with freeing unassigned pointer.
So it is more than just a recommendation sometimes.

-- 
Regards,
Sudeep

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  9:12       ` Ben Horgan
@ 2025-08-27  9:21         ` Zihuan Zhang
  0 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-27  9:21 UTC (permalink / raw)
  To: Ben Horgan, Rafael J . wysocki, Viresh Kumar, Catalin Marinas,
	Will Deacon, Sean Christopherson, Paolo Bonzini, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, Markus Mayer,
	Florian Fainelli, Srinivas Pandruvada, Madhavan Srinivasan,
	Michael Ellerman, Krzysztof Kozlowski, Alim Akhtar,
	Thierry Reding, Jonathan Hunter, MyungJoo Ham, Kyungmin Park,
	Chanwoo Choi, Jani Nikula, Joonas Lahtinen, Rodrigo Vivi,
	Tvrtko Ursulin, David Airlie, Simona Vetter, Daniel Lezcano,
	Sascha Hauer, Shawn Guo, Eduardo Valentin, Keerthy,
	Matthias Brugger, AngeloGioacchino Del Regno
  Cc: zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel

Hi,

在 2025/8/27 17:12, Ben Horgan 写道:
> Hi Zihuan,
>
> On 8/27/25 09:55, Zihuan Zhang wrote:
>> Hi,
>>
>> 在 2025/8/27 16:30, Ben Horgan 写道:
>>> Hi Zihuan,
>>>
>>> On 8/27/25 03:31, Zihuan Zhang 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>
>>>> ---
>>>>    arch/arm64/kernel/topology.c | 9 +++------
>>>>    1 file changed, 3 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
>>>> index 5d07ee85bdae..e3cb6d54f35b 100644
>>>> --- a/arch/arm64/kernel/topology.c
>>>> +++ b/arch/arm64/kernel/topology.c
>>>> @@ -307,17 +307,16 @@ int arch_freq_get_on_cpu(int cpu)
>>>>             */
>>>>            if (!housekeeping_cpu(cpu, HK_TYPE_TICK) ||
>>>>                time_is_before_jiffies(last_update +
>>>> msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) {
>>>> -            struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
>>>> +            struct cpufreq_policy *policy __free(put_cpufreq_policy);
>>> Based on the guidance, in include/linux/cleanup.h, I would expect the
>>> assignment to be done on this line.
>>>
>>> "...the recommendation is to always define and assign variables in one
>>>    * statement and not group variable definitions at the top of the
>>>    * function when __free() is used."
>>
>> The reason I split the assignment into multiple lines is because
>> scripts/checkpatch.pl gave a warning about the line being too long.
>>
>> But if you think a single-line assignment is better, I will modify it
>> accordingly.
> My preference, for what it's worth, would be to keep it one statement
> and split the line after the =.


Okay,  I will update it that way. Thanks.

>>>>                int ref_cpu;
>>>>    +            policy = cpufreq_cpu_get(cpu);
>>>>                if (!policy)
>>>>                    return -EINVAL;
>>>>                  if (!cpumask_intersects(policy->related_cpus,
>>>> -                        housekeeping_cpumask(HK_TYPE_TICK))) {
>>>> -                cpufreq_cpu_put(policy);
>>>> +                        housekeeping_cpumask(HK_TYPE_TICK)))
>>>>                    return -EOPNOTSUPP;
>>>> -            }
>>>>                  for_each_cpu_wrap(ref_cpu, policy->cpus, cpu + 1) {
>>>>                    if (ref_cpu == start_cpu) {
>>>> @@ -329,8 +328,6 @@ int arch_freq_get_on_cpu(int cpu)
>>>>                        break;
>>>>                }
>>>>    -            cpufreq_cpu_put(policy);
>>>> -
>>>>                if (ref_cpu >= nr_cpu_ids)
>>>>                    /* No alternative to pull info from */
>>>>                    return -EAGAIN;
>>> Thanks,
>>>
>>> Ben
>>>
> Thanks,
>
> Ben
>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 02/18] KVM: x86: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 ` [PATCH v2 02/18] KVM: x86: " Zihuan Zhang
@ 2025-08-27 14:13   ` Sean Christopherson
  2025-08-28  1:17     ` Zihuan Zhang
  0 siblings, 1 reply; 40+ messages in thread
From: Sean Christopherson @ 2025-08-27 14:13 UTC (permalink / raw)
  To: Zihuan Zhang
  Cc: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, Markus Mayer, Florian Fainelli, Srinivas Pandruvada,
	Madhavan Srinivasan, Michael Ellerman, Krzysztof Kozlowski,
	Alim Akhtar, Thierry Reding, Jonathan Hunter, MyungJoo Ham,
	Kyungmin Park, Chanwoo Choi, Jani Nikula, Joonas Lahtinen,
	Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
	Daniel Lezcano, Sascha Hauer, Shawn Guo, Eduardo Valentin,
	Keerthy, Matthias Brugger, AngeloGioacchino Del Regno,
	zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel

On Wed, Aug 27, 2025, Zihuan Zhang 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>
> ---
>  arch/x86/kvm/x86.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index a1c49bc681c4..2a825f4ec701 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9492,16 +9492,14 @@ static void kvm_timer_init(void)
>  		max_tsc_khz = tsc_khz;
>  
>  		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
> -			struct cpufreq_policy *policy;
> +			struct cpufreq_policy *policy __free(put_cpufreq_policy);
>  			int cpu;
>  
>  			cpu = get_cpu();
>  			policy = cpufreq_cpu_get(cpu);
> -			if (policy) {
> -				if (policy->cpuinfo.max_freq)
> -					max_tsc_khz = policy->cpuinfo.max_freq;
> -				cpufreq_cpu_put(policy);
> -			}
> +			if (policy && policy->cpuinfo.max_freq)
> +				max_tsc_khz = policy->cpuinfo.max_freq;
> +
>  			put_cpu();

Hmm, this is technically buggy.  __free() won't invoke put_cpufreq_policy() until
policy goes out of scope, and so using __free() means the code is effectively:

		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
			struct cpufreq_policy *policy;
			int cpu;

			cpu = get_cpu();
			policy = cpufreq_cpu_get(cpu);
			if (policy && policy->cpuinfo.max_freq)
				max_tsc_khz = policy->cpuinfo.max_freq;
			put_cpu();

			if (policy)
				cpufreq_cpu_put(policy);
		}

That's "fine" because the policy isn't truly referenced after preemption is
disabled, the lifecycle of the policy doesn't rely on preemption being disabled,
and KVM doesn't actually care which CPU is used to get the max frequency, i.e.
this would technically be "fine" too:

		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
			struct cpufreq_policy *policy;
			int cpu;

			cpu = get_cpu();
			policy = cpufreq_cpu_get(cpu);
			put_cpu();

			if (policy && policy->cpuinfo.max_freq)
				max_tsc_khz = policy->cpuinfo.max_freq;

			if (policy)
				cpufreq_cpu_put(policy);
		}

But given that the code we have today is perfectly readable, I don't see any
reason to switch to __free() given that's it's technically flawed.  So I'm very
strongly inclined to skip this patch and keep things as-is.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 02/18] KVM: x86: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27 14:13   ` Sean Christopherson
@ 2025-08-28  1:17     ` Zihuan Zhang
  2025-08-28 17:15       ` Sean Christopherson
  0 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-28  1:17 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, Markus Mayer, Florian Fainelli, Srinivas Pandruvada,
	Madhavan Srinivasan, Michael Ellerman, Krzysztof Kozlowski,
	Alim Akhtar, Thierry Reding, Jonathan Hunter, MyungJoo Ham,
	Kyungmin Park, Chanwoo Choi, Jani Nikula, Joonas Lahtinen,
	Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
	Daniel Lezcano, Sascha Hauer, Shawn Guo, Eduardo Valentin,
	Keerthy, Matthias Brugger, AngeloGioacchino Del Regno,
	zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel

Hi,

在 2025/8/27 22:13, Sean Christopherson 写道:
> On Wed, Aug 27, 2025, Zihuan Zhang 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>
>> ---
>>   arch/x86/kvm/x86.c | 10 ++++------
>>   1 file changed, 4 insertions(+), 6 deletions(-)
>>
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index a1c49bc681c4..2a825f4ec701 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -9492,16 +9492,14 @@ static void kvm_timer_init(void)
>>   		max_tsc_khz = tsc_khz;
>>   
>>   		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
>> -			struct cpufreq_policy *policy;
>> +			struct cpufreq_policy *policy __free(put_cpufreq_policy);
>>   			int cpu;
>>   
>>   			cpu = get_cpu();
>>   			policy = cpufreq_cpu_get(cpu);
>> -			if (policy) {
>> -				if (policy->cpuinfo.max_freq)
>> -					max_tsc_khz = policy->cpuinfo.max_freq;
>> -				cpufreq_cpu_put(policy);
>> -			}
>> +			if (policy && policy->cpuinfo.max_freq)
>> +				max_tsc_khz = policy->cpuinfo.max_freq;
>> +
>>   			put_cpu();
> Hmm, this is technically buggy.  __free() won't invoke put_cpufreq_policy() until
> policy goes out of scope, and so using __free() means the code is effectively:
>
> 		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
> 			struct cpufreq_policy *policy;
> 			int cpu;
>
> 			cpu = get_cpu();
> 			policy = cpufreq_cpu_get(cpu);
> 			if (policy && policy->cpuinfo.max_freq)
> 				max_tsc_khz = policy->cpuinfo.max_freq;
> 			put_cpu();
>
> 			if (policy)
> 				cpufreq_cpu_put(policy);
> 		}
>
> That's "fine" because the policy isn't truly referenced after preemption is
> disabled, the lifecycle of the policy doesn't rely on preemption being disabled,
> and KVM doesn't actually care which CPU is used to get the max frequency, i.e.
> this would technically be "fine" too:
>
> 		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
> 			struct cpufreq_policy *policy;
> 			int cpu;
>
> 			cpu = get_cpu();
> 			policy = cpufreq_cpu_get(cpu);
> 			put_cpu();
>
> 			if (policy && policy->cpuinfo.max_freq)
> 				max_tsc_khz = policy->cpuinfo.max_freq;
>
> 			if (policy)
> 				cpufreq_cpu_put(policy);
> 		}
>
> But given that the code we have today is perfectly readable, I don't see any
> reason to switch to __free() given that's it's technically flawed.  So I'm very
> strongly inclined to skip this patch and keep things as-is.


Yes, this will indeed change the execution order.
Can you accept that? Personally, I don’t think it’s ideal either.

		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
  			int cpu;
			cpu = get_cpu();
			{
				struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
				if (policy && policy->cpuinfo.max_freq)
					max_tsc_khz = policy->cpuinfo.max_freq;
			}
			put_cpu();

                                             }

Other places may also have the same issue,

maybe we should consider introducing a macro to handle this properly,
so that initialization and cleanup are well defined without changing
the existing order unexpected.

like this:

#define WITH_CPUFREQ_POLICY(cpu) {\

for(struct cpufreq_policy *policy __free(put_cpufreq_policy) =  \
			cpufreq_cpu_get(cpu);			\
			policy;)

Then Use it:

		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
  			int cpu;
			cpu = get_cpu();
			WITH_CPUFREQ_POLICY(cpu){
				if (policy->cpuinfo.max_freq)
					max_tsc_khz = policy->cpuinfo.max_freq;
			}
			put_cpu();

                                             }


^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference
       [not found]     ` <1756341899099493.57.seg@mailgw.kylinos.cn>
@ 2025-08-28  2:32       ` Zihuan Zhang
  0 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-28  2:32 UTC (permalink / raw)
  To: Sudeep Holla, Ben Horgan
  Cc: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel


在 2025/8/27 17:17, Sudeep Holla 写道:
> On Wed, Aug 27, 2025 at 09:30:13AM +0100, Ben Horgan wrote:
>> Hi Zihuan,
>>
>> On 8/27/25 03:31, Zihuan Zhang 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>
>>> ---
>>>   arch/arm64/kernel/topology.c | 9 +++------
>>>   1 file changed, 3 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
>>> index 5d07ee85bdae..e3cb6d54f35b 100644
>>> --- a/arch/arm64/kernel/topology.c
>>> +++ b/arch/arm64/kernel/topology.c
>>> @@ -307,17 +307,16 @@ int arch_freq_get_on_cpu(int cpu)
>>>   		 */
>>>   		if (!housekeeping_cpu(cpu, HK_TYPE_TICK) ||
>>>   		    time_is_before_jiffies(last_update + msecs_to_jiffies(AMU_SAMPLE_EXP_MS))) {
>>> -			struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
>>> +			struct cpufreq_policy *policy __free(put_cpufreq_policy);
>> Based on the guidance, in include/linux/cleanup.h, I would expect the
>> assignment to be done on this line.
>>
>> "...the recommendation is to always define and assign variables in one
>>   * statement and not group variable definitions at the top of the
>>   * function when __free() is used."
>>
> Agreed. I did something similar recently and there was a code path where
> variable wasn't initialised and ended up with freeing unassigned pointer.
> So it is more than just a recommendation sometimes.
>
Thanks a lot for your suggestions.

We are also considering introducing a WITH_CPUFREQ_POLICY wrapper to 
encapsulate the cpufreq_cpu_get/put usage, so that the release order 
won’t be accidentally changed.

Link: 
https://lore.kernel.org/all/874d821e-8ea3-40ac-921b-c19bb380a456@kylinos.cn/

Do you have any suggestions or preferences on this direction?



^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 03/18] ACPI: processor: thermal: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 ` [PATCH v2 03/18] ACPI: processor: thermal: " Zihuan Zhang
@ 2025-08-28  9:40   ` Rafael J. Wysocki
  2025-08-29  1:09     ` Zihuan Zhang
  0 siblings, 1 reply; 40+ messages in thread
From: Rafael J. Wysocki @ 2025-08-28  9:40 UTC (permalink / raw)
  To: Zihuan Zhang
  Cc: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Sudeep Holla, Yicong Yang, linux-pm, x86, kvm, linux-acpi,
	linuxppc-dev, linux-samsung-soc, linux-arm-kernel, linux-tegra,
	intel-gfx, dri-devel, imx, linux-omap, linux-mediatek,
	linux-kernel

On Wed, Aug 27, 2025 at 4:33 AM 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 | 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.

>  }
>
>  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.

>         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",
> --

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 02/18] KVM: x86: Use __free(put_cpufreq_policy) for policy reference
  2025-08-28  1:17     ` Zihuan Zhang
@ 2025-08-28 17:15       ` Sean Christopherson
  0 siblings, 0 replies; 40+ messages in thread
From: Sean Christopherson @ 2025-08-28 17:15 UTC (permalink / raw)
  To: Zihuan Zhang
  Cc: Rafael J . wysocki, Viresh Kumar, Catalin Marinas, Will Deacon,
	Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, Markus Mayer, Florian Fainelli, Srinivas Pandruvada,
	Madhavan Srinivasan, Michael Ellerman, Krzysztof Kozlowski,
	Alim Akhtar, Thierry Reding, Jonathan Hunter, MyungJoo Ham,
	Kyungmin Park, Chanwoo Choi, Jani Nikula, Joonas Lahtinen,
	Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
	Daniel Lezcano, Sascha Hauer, Shawn Guo, Eduardo Valentin,
	Keerthy, Matthias Brugger, AngeloGioacchino Del Regno,
	zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel

On Thu, Aug 28, 2025, Zihuan Zhang wrote:
> > Hmm, this is technically buggy.  __free() won't invoke put_cpufreq_policy() until
> > policy goes out of scope, and so using __free() means the code is effectively:
> > 
> > 		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
> > 			struct cpufreq_policy *policy;
> > 			int cpu;
> > 
> > 			cpu = get_cpu();
> > 			policy = cpufreq_cpu_get(cpu);
> > 			if (policy && policy->cpuinfo.max_freq)
> > 				max_tsc_khz = policy->cpuinfo.max_freq;
> > 			put_cpu();
> > 
> > 			if (policy)
> > 				cpufreq_cpu_put(policy);
> > 		}

...

> Yes, this will indeed change the execution order.
> Can you accept that? 

No, because it's buggy.

> Personally, I don’t think it’s ideal either.
> 
> 		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
>  			int cpu;
> 			cpu = get_cpu();
> 			{
> 				struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> 				if (policy && policy->cpuinfo.max_freq)
> 					max_tsc_khz = policy->cpuinfo.max_freq;
> 			}
> 			put_cpu();
> 
>                                             }
> 
> Other places may also have the same issue,
> 
> maybe we should consider introducing a macro to handle this properly,
> so that initialization and cleanup are well defined without changing
> the existing order unexpected.
> 
> like this:
> 
> #define WITH_CPUFREQ_POLICY(cpu) {\
> 
> for(struct cpufreq_policy *policy __free(put_cpufreq_policy) =  \
> 			cpufreq_cpu_get(cpu);			\
> 			policy;)
> 
> Then Use it:
> 
> 		if (IS_ENABLED(CONFIG_CPU_FREQ)) {
>  			int cpu;
> 			cpu = get_cpu();
> 			WITH_CPUFREQ_POLICY(cpu){
> 				if (policy->cpuinfo.max_freq)
> 					max_tsc_khz = policy->cpuinfo.max_freq;
> 			}
> 			put_cpu();

This all feels very forced, in the sense that we have a shiny new tool and are
trying to use it everywhere without thinking critically about whether or not
doing so is actually an improvement.

At a glance, this is literally the only instance in the entire kernel where the
CPU to use is grabbed immediately before the policy.
 
  $ git grep -B 20 cpufreq_cpu_get | grep -e get_cpu -e smp_processor_id
  arch/x86/kvm/x86.c-			cpu = get_cpu();
  drivers/cpufreq/cppc_cpufreq.c-static int cppc_get_cpu_power(struct device *cpu_dev,
  drivers/cpufreq/cppc_cpufreq.c-static int cppc_get_cpu_cost(struct device *cpu_dev, unsigned long KHz,
  drivers/cpufreq/mediatek-cpufreq-hw.c-mtk_cpufreq_get_cpu_power(struct device *cpu_dev, unsigned long *uW,

Probably because KVM's usage is rather bizarre and honestly kind of dumb.  But
KVM has had this behavior for 15+ years, so as weird as it is, I'm not inclined
to change it without a really, really strong reason to do so, e.g. to iterate
over all CPUs or something.

So given that this is the only intance of the problem patter, I think it makes
sense to leave KVM as-is, and not spend a bunch of time trying to figure out how
to make KVM's usage play nice with __free().

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 03/18] ACPI: processor: thermal: Use __free(put_cpufreq_policy) for policy reference
  2025-08-28  9:40   ` Rafael J. Wysocki
@ 2025-08-29  1:09     ` Zihuan Zhang
  0 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-29  1:09 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Viresh Kumar, Catalin Marinas, Will Deacon, Sean Christopherson,
	Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, Markus Mayer, Florian Fainelli, Srinivas Pandruvada,
	Madhavan Srinivasan, Michael Ellerman, Krzysztof Kozlowski,
	Alim Akhtar, Thierry Reding, Jonathan Hunter, MyungJoo Ham,
	Kyungmin Park, Chanwoo Choi, Jani Nikula, Joonas Lahtinen,
	Rodrigo Vivi, Tvrtko Ursulin, David Airlie, Simona Vetter,
	Daniel Lezcano, Sascha Hauer, Shawn Guo, Eduardo Valentin,
	Keerthy, Matthias Brugger, AngeloGioacchino Del Regno,
	zhenglifeng, H . Peter Anvin, Zhang Rui, Len Brown,
	Nicholas Piggin, Christophe Leroy, Lukasz Luba,
	Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
	Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
	Yicong Yang, linux-pm, x86, kvm, linux-acpi, linuxppc-dev,
	linux-samsung-soc, linux-arm-kernel, linux-tegra, intel-gfx,
	dri-devel, imx, linux-omap, linux-mediatek, linux-kernel


在 2025/8/28 17:40, Rafael J. Wysocki 写道:
> On Wed, Aug 27, 2025 at 4:33 AM 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 | 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",
>> --

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 04/18] cpufreq: brcmstb-avs-cpufreq: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 ` [PATCH v2 04/18] cpufreq: brcmstb-avs-cpufreq: " Zihuan Zhang
@ 2025-08-29  5:59   ` Viresh Kumar
  2025-08-29  6:16     ` Zihuan Zhang
  0 siblings, 1 reply; 40+ messages in thread
From: Viresh Kumar @ 2025-08-29  5:59 UTC (permalink / raw)
  To: Zihuan Zhang
  Cc: Rafael J . wysocki, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Sudeep Holla, Yicong Yang, linux-pm, x86, kvm, linux-acpi,
	linuxppc-dev, linux-samsung-soc, linux-arm-kernel, linux-tegra,
	intel-gfx, dri-devel, imx, linux-omap, linux-mediatek,
	linux-kernel

On 27-08-25, 10:31, Zihuan Zhang 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/cpufreq/brcmstb-avs-cpufreq.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Applied. Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 05/18] cpufreq: CPPC: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 ` [PATCH v2 05/18] cpufreq: CPPC: " Zihuan Zhang
@ 2025-08-29  6:04   ` Viresh Kumar
  0 siblings, 0 replies; 40+ messages in thread
From: Viresh Kumar @ 2025-08-29  6:04 UTC (permalink / raw)
  To: Zihuan Zhang
  Cc: Rafael J . wysocki, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Sudeep Holla, Yicong Yang, linux-pm, x86, kvm, linux-acpi,
	linuxppc-dev, linux-samsung-soc, linux-arm-kernel, linux-tegra,
	intel-gfx, dri-devel, imx, linux-omap, linux-mediatek,
	linux-kernel

On 27-08-25, 10:31, Zihuan Zhang 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/cpufreq/cppc_cpufreq.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Applied. Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 10/18] cpufreq: s5pv210: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 ` [PATCH v2 10/18] cpufreq: s5pv210: " Zihuan Zhang
@ 2025-08-29  6:13   ` Viresh Kumar
  0 siblings, 0 replies; 40+ messages in thread
From: Viresh Kumar @ 2025-08-29  6:13 UTC (permalink / raw)
  To: Zihuan Zhang
  Cc: Rafael J . wysocki, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Sudeep Holla, Yicong Yang, linux-pm, x86, kvm, linux-acpi,
	linuxppc-dev, linux-samsung-soc, linux-arm-kernel, linux-tegra,
	intel-gfx, dri-devel, imx, linux-omap, linux-mediatek,
	linux-kernel

On 27-08-25, 10:31, Zihuan Zhang 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/cpufreq/s5pv210-cpufreq.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
> index 76c888ed8d16..95f1568e9530 100644
> --- a/drivers/cpufreq/s5pv210-cpufreq.c
> +++ b/drivers/cpufreq/s5pv210-cpufreq.c
> @@ -555,7 +555,7 @@ static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this,
>  						 unsigned long event, void *ptr)
>  {
>  	int ret;
> -	struct cpufreq_policy *policy;
> +	struct cpufreq_policy *policy __free(put_cpufreq_policy);
>  
>  	policy = cpufreq_cpu_get(0);
>  	if (!policy) {
> @@ -564,7 +564,6 @@ static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this,
>  	}
>  
>  	ret = cpufreq_driver_target(policy, SLEEP_FREQ, 0);
> -	cpufreq_cpu_put(policy);
>  
>  	if (ret < 0)
>  		return NOTIFY_BAD;

Merged with minor change:

diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
index 95f1568e9530..4215621deb3f 100644
--- a/drivers/cpufreq/s5pv210-cpufreq.c
+++ b/drivers/cpufreq/s5pv210-cpufreq.c
@@ -554,10 +554,9 @@ static int s5pv210_cpu_init(struct cpufreq_policy *policy)
 static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this,
                                                 unsigned long event, void *ptr)
 {
+       struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(0);
        int ret;
-       struct cpufreq_policy *policy __free(put_cpufreq_policy);

-       policy = cpufreq_cpu_get(0);
        if (!policy) {
                pr_debug("cpufreq: get no policy for cpu0\n");
                return NOTIFY_BAD;

-- 
viresh

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 04/18] cpufreq: brcmstb-avs-cpufreq: Use __free(put_cpufreq_policy) for policy reference
  2025-08-29  5:59   ` Viresh Kumar
@ 2025-08-29  6:16     ` Zihuan Zhang
  2025-08-29  6:26       ` Viresh Kumar
  0 siblings, 1 reply; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-29  6:16 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J . wysocki, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Sudeep Holla, Yicong Yang, linux-pm, x86, kvm, linux-acpi,
	linuxppc-dev, linux-samsung-soc, linux-arm-kernel, linux-tegra,
	intel-gfx, dri-devel, imx, linux-omap, linux-mediatek,
	linux-kernel


在 2025/8/29 13:59, Viresh Kumar 写道:
> On 27-08-25, 10:31, Zihuan Zhang 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/cpufreq/brcmstb-avs-cpufreq.c | 4 +---
>>   1 file changed, 1 insertion(+), 3 deletions(-)
> Applied. Thanks.
>

Thanks for applying the patch!

I’ve been thinking further — instead of using __free directly, maybe we 
could introduce a small macro wrapper around it to make the release 
scope more controllable and consistent.

Link: 
https://lore.kernel.org/all/6174bcc8-30f5-479b-bac6-f42eb1232b4d@kylinos.cn/

Do you think this would be a better approach, or should we just stick 
with the current use of __free?




^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 08/18] cpufreq: mediatek: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 ` [PATCH v2 08/18] cpufreq: mediatek: " Zihuan Zhang
@ 2025-08-29  6:18   ` Viresh Kumar
  0 siblings, 0 replies; 40+ messages in thread
From: Viresh Kumar @ 2025-08-29  6:18 UTC (permalink / raw)
  To: Zihuan Zhang
  Cc: Rafael J . wysocki, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Sudeep Holla, Yicong Yang, linux-pm, x86, kvm, linux-acpi,
	linuxppc-dev, linux-samsung-soc, linux-arm-kernel, linux-tegra,
	intel-gfx, dri-devel, imx, linux-omap, linux-mediatek,
	linux-kernel

On 27-08-25, 10:31, Zihuan Zhang 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/cpufreq/mediatek-cpufreq.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
> index f3f02c4b6888..1fae060e16d9 100644
> --- a/drivers/cpufreq/mediatek-cpufreq.c
> +++ b/drivers/cpufreq/mediatek-cpufreq.c
> @@ -320,7 +320,7 @@ static int mtk_cpufreq_opp_notifier(struct notifier_block *nb,
>  	struct dev_pm_opp *new_opp;
>  	struct mtk_cpu_dvfs_info *info;
>  	unsigned long freq, volt;
> -	struct cpufreq_policy *policy;
> +	struct cpufreq_policy *policy __free(put_cpufreq_policy);
>  	int ret = 0;
>  
>  	info = container_of(nb, struct mtk_cpu_dvfs_info, opp_nb);
> @@ -354,11 +354,9 @@ static int mtk_cpufreq_opp_notifier(struct notifier_block *nb,
>  
>  			dev_pm_opp_put(new_opp);
>  			policy = cpufreq_cpu_get(info->opp_cpu);
> -			if (policy) {
> +			if (policy)
>  				cpufreq_driver_target(policy, freq / 1000,
>  						      CPUFREQ_RELATION_L);
> -				cpufreq_cpu_put(policy);
> -			}
>  		}
>  	}

Merged with:

diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index 1fae060e16d9..fae062a6431f 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -320,7 +320,6 @@ static int mtk_cpufreq_opp_notifier(struct notifier_block *nb,
        struct dev_pm_opp *new_opp;
        struct mtk_cpu_dvfs_info *info;
        unsigned long freq, volt;
-       struct cpufreq_policy *policy __free(put_cpufreq_policy);
        int ret = 0;

        info = container_of(nb, struct mtk_cpu_dvfs_info, opp_nb);
@@ -353,7 +352,9 @@ static int mtk_cpufreq_opp_notifier(struct notifier_block *nb,
                        }

                        dev_pm_opp_put(new_opp);
-                       policy = cpufreq_cpu_get(info->opp_cpu);
+
+                       struct cpufreq_policy *policy __free(put_cpufreq_policy)
+                               = cpufreq_cpu_get(info->opp_cpu);
                        if (policy)
                                cpufreq_driver_target(policy, freq / 1000,
                                                      CPUFREQ_RELATION_L);

-- 
viresh

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 04/18] cpufreq: brcmstb-avs-cpufreq: Use __free(put_cpufreq_policy) for policy reference
  2025-08-29  6:16     ` Zihuan Zhang
@ 2025-08-29  6:26       ` Viresh Kumar
  2025-08-29  6:32         ` Zihuan Zhang
  0 siblings, 1 reply; 40+ messages in thread
From: Viresh Kumar @ 2025-08-29  6:26 UTC (permalink / raw)
  To: Zihuan Zhang
  Cc: Rafael J . wysocki, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Sudeep Holla, Yicong Yang, linux-pm, x86, kvm, linux-acpi,
	linuxppc-dev, linux-samsung-soc, linux-arm-kernel, linux-tegra,
	intel-gfx, dri-devel, imx, linux-omap, linux-mediatek,
	linux-kernel

On 29-08-25, 14:16, Zihuan Zhang wrote:
> Thanks for applying the patch!
> 
> I’ve been thinking further — instead of using __free directly, maybe we
> could introduce a small macro wrapper around it to make the release scope
> more controllable and consistent.
> 
> Link:
> https://lore.kernel.org/all/6174bcc8-30f5-479b-bac6-f42eb1232b4d@kylinos.cn/
> 
> Do you think this would be a better approach, or should we just stick with
> the current use of __free?

Lets keep it simple for now and use __free directly. And keep this
similar with other parts of the kernel.

-- 
viresh

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 11/18] cpufreq: tegra186: Use __free(put_cpufreq_policy) for policy reference
  2025-08-27  2:31 ` [PATCH v2 11/18] cpufreq: tegra186: " Zihuan Zhang
@ 2025-08-29  6:29   ` Viresh Kumar
  0 siblings, 0 replies; 40+ messages in thread
From: Viresh Kumar @ 2025-08-29  6:29 UTC (permalink / raw)
  To: Zihuan Zhang
  Cc: Rafael J . wysocki, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Sudeep Holla, Yicong Yang, linux-pm, x86, kvm, linux-acpi,
	linuxppc-dev, linux-samsung-soc, linux-arm-kernel, linux-tegra,
	intel-gfx, dri-devel, imx, linux-omap, linux-mediatek,
	linux-kernel

On 27-08-25, 10:31, Zihuan Zhang 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/cpufreq/tegra186-cpufreq.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/cpufreq/tegra186-cpufreq.c b/drivers/cpufreq/tegra186-cpufreq.c
> index cbabb726c664..4d71e262a729 100644
> --- a/drivers/cpufreq/tegra186-cpufreq.c
> +++ b/drivers/cpufreq/tegra186-cpufreq.c
> @@ -105,7 +105,7 @@ static unsigned int tegra186_cpufreq_get(unsigned int cpu)
>  {
>  	struct tegra186_cpufreq_data *data = cpufreq_get_driver_data();
>  	struct tegra186_cpufreq_cluster *cluster;
> -	struct cpufreq_policy *policy;
> +	struct cpufreq_policy *policy __free(put_cpufreq_policy);
>  	unsigned int edvd_offset, cluster_id;
>  	u32 ndiv;
>  
> @@ -117,7 +117,6 @@ static unsigned int tegra186_cpufreq_get(unsigned int cpu)
>  	ndiv = readl(data->regs + edvd_offset) & EDVD_CORE_VOLT_FREQ_F_MASK;
>  	cluster_id = data->cpus[policy->cpu].bpmp_cluster_id;
>  	cluster = &data->clusters[cluster_id];
> -	cpufreq_cpu_put(policy);
>  
>  	return (cluster->ref_clk_khz * ndiv) / cluster->div;

Merged with:

diff --git a/drivers/cpufreq/tegra186-cpufreq.c b/drivers/cpufreq/tegra186-cpufreq.c
index 4d71e262a729..4270686fc3e3 100644
--- a/drivers/cpufreq/tegra186-cpufreq.c
+++ b/drivers/cpufreq/tegra186-cpufreq.c
@@ -103,13 +103,12 @@ static int tegra186_cpufreq_set_target(struct cpufreq_policy *policy,
 
 static unsigned int tegra186_cpufreq_get(unsigned int cpu)
 {
+       struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
        struct tegra186_cpufreq_data *data = cpufreq_get_driver_data();
        struct tegra186_cpufreq_cluster *cluster;
-       struct cpufreq_policy *policy __free(put_cpufreq_policy);
        unsigned int edvd_offset, cluster_id;
        u32 ndiv;
 
-       policy = cpufreq_cpu_get(cpu);
        if (!policy)
                return 0;
 

-- 
viresh

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH v2 04/18] cpufreq: brcmstb-avs-cpufreq: Use __free(put_cpufreq_policy) for policy reference
  2025-08-29  6:26       ` Viresh Kumar
@ 2025-08-29  6:32         ` Zihuan Zhang
  0 siblings, 0 replies; 40+ messages in thread
From: Zihuan Zhang @ 2025-08-29  6:32 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J . wysocki, Catalin Marinas, Will Deacon,
	Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, Markus Mayer, Florian Fainelli,
	Srinivas Pandruvada, Madhavan Srinivasan, Michael Ellerman,
	Krzysztof Kozlowski, Alim Akhtar, Thierry Reding, Jonathan Hunter,
	MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
	Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
	Eduardo Valentin, Keerthy, Matthias Brugger,
	AngeloGioacchino Del Regno, zhenglifeng, H . Peter Anvin,
	Zhang Rui, Len Brown, Nicholas Piggin, Christophe Leroy,
	Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
	Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
	Sudeep Holla, Yicong Yang, linux-pm, x86, kvm, linux-acpi,
	linuxppc-dev, linux-samsung-soc, linux-arm-kernel, linux-tegra,
	intel-gfx, dri-devel, imx, linux-omap, linux-mediatek,
	linux-kernel


在 2025/8/29 14:26, Viresh Kumar 写道:
> On 29-08-25, 14:16, Zihuan Zhang wrote:
>> Thanks for applying the patch!
>>
>> I’ve been thinking further — instead of using __free directly, maybe we
>> could introduce a small macro wrapper around it to make the release scope
>> more controllable and consistent.
>>
>> Link:
>> https://lore.kernel.org/all/6174bcc8-30f5-479b-bac6-f42eb1232b4d@kylinos.cn/
>>
>> Do you think this would be a better approach, or should we just stick with
>> the current use of __free?
> Lets keep it simple for now and use __free directly. And keep this
> similar with other parts of the kernel.


Got it. Thanks!


^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2025-08-29  6:32 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27  2:31 [PATCH v2 00/18] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 01/18] arm64: topology: Use __free(put_cpufreq_policy) for policy reference Zihuan Zhang
2025-08-27  8:30   ` Ben Horgan
2025-08-27  8:55     ` Zihuan Zhang
2025-08-27  9:12       ` Ben Horgan
2025-08-27  9:21         ` Zihuan Zhang
2025-08-27  9:17     ` Sudeep Holla
     [not found]     ` <1756341899099493.57.seg@mailgw.kylinos.cn>
2025-08-28  2:32       ` Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 02/18] KVM: x86: " Zihuan Zhang
2025-08-27 14:13   ` Sean Christopherson
2025-08-28  1:17     ` Zihuan Zhang
2025-08-28 17:15       ` Sean Christopherson
2025-08-27  2:31 ` [PATCH v2 03/18] ACPI: processor: thermal: " Zihuan Zhang
2025-08-28  9:40   ` Rafael J. Wysocki
2025-08-29  1:09     ` Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 04/18] cpufreq: brcmstb-avs-cpufreq: " Zihuan Zhang
2025-08-29  5:59   ` Viresh Kumar
2025-08-29  6:16     ` Zihuan Zhang
2025-08-29  6:26       ` Viresh Kumar
2025-08-29  6:32         ` Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 05/18] cpufreq: CPPC: " Zihuan Zhang
2025-08-29  6:04   ` Viresh Kumar
2025-08-27  2:31 ` [PATCH v2 06/18] cpufreq: intel_pstate: " Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 07/18] cpufreq: longhaul: " Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 08/18] cpufreq: mediatek: " Zihuan Zhang
2025-08-29  6:18   ` Viresh Kumar
2025-08-27  2:31 ` [PATCH v2 09/18] cpufreq: powernv: " Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 10/18] cpufreq: s5pv210: " Zihuan Zhang
2025-08-29  6:13   ` Viresh Kumar
2025-08-27  2:31 ` [PATCH v2 11/18] cpufreq: tegra186: " Zihuan Zhang
2025-08-29  6:29   ` Viresh Kumar
2025-08-27  2:31 ` [PATCH v2 12/18] PM / devfreq: " Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 13/18] drm/i915: " Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 14/18] cpufreq: powerpc: macintosh: " Zihuan Zhang
2025-08-27  2:31 ` [PATCH v2 15/18] powercap: dtpm_cpu: " Zihuan Zhang
2025-08-27  2:32 ` [PATCH v2 16/18] thermal: imx: " Zihuan Zhang
2025-08-27  2:32 ` [PATCH v2 17/18] thermal/drivers/ti-soc-thermal: " Zihuan Zhang
2025-08-27  2:32 ` [PATCH v2 18/18] PM: EM: " Zihuan Zhang
2025-08-27  3:50 ` [PATCH v2 15/18] powercap: dtpm_cpu: " Zihuan Zhang
2025-08-27  5:21   ` Zihuan Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).