* [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references
@ 2025-09-05 13:24 Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 1/6] arm64: topology: Use scope-based cleanup helper Zihuan Zhang
` (6 more replies)
0 siblings, 7 replies; 17+ messages in thread
From: Zihuan Zhang @ 2025-09-05 13:24 UTC (permalink / raw)
To: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy
Cc: Ben Horgan, zhenglifeng, Zhang Rui, Len Brown, Lukasz Luba,
Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
Yicong Yang, linux-pm, linux-acpi, linuxppc-dev, linux-arm-kernel,
intel-gfx, dri-devel, imx, linux-omap, 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 6 patches as they touch different subsystems
and are maintained by different people. There is no functional change.
V5:
- drop 4 patches
- change return value int topology.c suggested by Jonathan Cameron
- fix code in processor_thermal.c suggested by Rafael and Jonathan Cameron
- fix code in intel_pstate.c suggested by Rafael
- fix code in governor_passive.c suggested Jonathan Cameron
- fix code in energy_model.c suggested by Rafael and Krzysztof Kozlowski
V4:
- Fix compile error in topology.c
- drop 2 patches
- Move code into a function in processor_thermal.c
- Move code into a function in intel_pstate.c
- Move policy declare in dtpm_cpu.c
- Fix compile error in imx_thermal.c
- Fix compile error in ti-thermal-common.c
- Fix compile error in energy_model.c
V3:
- drop patch 'KVM: x86: Use __free(put_cpufreq_policy) for policy reference'
- removed 5 patches which has been applied
- Consolidate CPUFreq policy assignments and allocations into one line,
suggested by Ben Horgan
- Change cpu_has_cpufreq() return type to bool, following Rafael's suggestion
- Change the title to 'Use scope-based cleanup helper'
V2:
- Fix compile error in powernv-cpufreq.c
- Split patch to separate logical changes
Zihuan Zhang (6):
arm64: topology: Use scope-based cleanup helper
ACPI: processor: thermal: Use scope-based cleanup helper
cpufreq: intel_pstate: Use scope-based cleanup helper
PM / devfreq: Use scope-based cleanup helper
drm/i915: Use scope-based cleanup helper
PM: EM: Use scope-based cleanup helper
arch/arm64/kernel/topology.c | 11 ++----
drivers/acpi/processor_thermal.c | 52 +++++++++++++------------
drivers/cpufreq/intel_pstate.c | 59 +++++++++++++++-------------
drivers/devfreq/governor_passive.c | 60 +++++++++++------------------
drivers/gpu/drm/i915/gt/intel_llc.c | 4 +-
kernel/power/energy_model.c | 9 +----
6 files changed, 89 insertions(+), 106 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v5 1/6] arm64: topology: Use scope-based cleanup helper
2025-09-05 13:24 [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
@ 2025-09-05 13:24 ` Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 2/6] ACPI: processor: thermal: " Zihuan Zhang
` (5 subsequent siblings)
6 siblings, 0 replies; 17+ messages in thread
From: Zihuan Zhang @ 2025-09-05 13:24 UTC (permalink / raw)
To: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy
Cc: Ben Horgan, zhenglifeng, Zhang Rui, Len Brown, Lukasz Luba,
Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
Yicong Yang, linux-pm, linux-acpi, linuxppc-dev, linux-arm-kernel,
intel-gfx, dri-devel, imx, linux-omap, 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>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
---
arch/arm64/kernel/topology.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index 5d07ee85bdae..07e2f5b5ade0 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -307,30 +307,27 @@ 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) =
+ cpufreq_cpu_get(info->opp_cpu);
int ref_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) {
/* Prevent verifying same CPU twice */
ref_cpu = nr_cpu_ids;
- break;
+ return -EAGAIN;
}
if (!idle_cpu(ref_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] 17+ messages in thread
* [PATCH v5 2/6] ACPI: processor: thermal: Use scope-based cleanup helper
2025-09-05 13:24 [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 1/6] arm64: topology: Use scope-based cleanup helper Zihuan Zhang
@ 2025-09-05 13:24 ` Zihuan Zhang
2025-09-05 20:17 ` Rafael J. Wysocki
2025-09-08 17:55 ` Rafael J. Wysocki
2025-09-05 13:24 ` [PATCH v5 3/6] cpufreq: intel_pstate: " Zihuan Zhang
` (4 subsequent siblings)
6 siblings, 2 replies; 17+ messages in thread
From: Zihuan Zhang @ 2025-09-05 13:24 UTC (permalink / raw)
To: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy
Cc: Ben Horgan, zhenglifeng, Zhang Rui, Len Brown, Lukasz Luba,
Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
Yicong Yang, linux-pm, linux-acpi, linuxppc-dev, linux-arm-kernel,
intel-gfx, dri-devel, imx, linux-omap, 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 | 52 +++++++++++++++++---------------
1 file changed, 27 insertions(+), 25 deletions(-)
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index 1219adb11ab9..460713d1414a 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -62,19 +62,14 @@ static int phys_package_first_cpu(int cpu)
return 0;
}
-static int cpu_has_cpufreq(unsigned int cpu)
+static bool cpu_has_cpufreq(unsigned int cpu)
{
- struct cpufreq_policy *policy;
-
if (!acpi_processor_cpufreq_init)
return 0;
- policy = cpufreq_cpu_get(cpu);
- if (policy) {
- cpufreq_cpu_put(policy);
- return 1;
- }
- return 0;
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
+
+ return policy != NULL;
}
static int cpufreq_get_max_state(unsigned int cpu)
@@ -93,12 +88,31 @@ static int cpufreq_get_cur_state(unsigned int cpu)
return reduction_step(cpu);
}
+static bool cpufreq_update_thermal_limit(unsigned int cpu, struct acpi_processor *pr)
+{
+ unsigned long max_freq;
+ int ret;
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
+
+ if (!policy)
+ return false;
+
+ max_freq = (policy->cpuinfo.max_freq *
+ (100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100;
+
+ ret = freq_qos_update_request(&pr->thermal_req, max_freq);
+ if (ret < 0) {
+ pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
+ pr->id, ret);
+ }
+
+ return true;
+}
+
static int cpufreq_set_cur_state(unsigned int cpu, int state)
{
- struct cpufreq_policy *policy;
struct acpi_processor *pr;
- unsigned long max_freq;
- int i, ret;
+ int i;
if (!cpu_has_cpufreq(cpu))
return 0;
@@ -120,20 +134,8 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
if (unlikely(!freq_qos_request_active(&pr->thermal_req)))
continue;
- policy = cpufreq_cpu_get(i);
- if (!policy)
+ if (!cpufreq_update_thermal_limit(i, pr))
return -EINVAL;
-
- max_freq = (policy->cpuinfo.max_freq *
- (100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100;
-
- cpufreq_cpu_put(policy);
-
- ret = freq_qos_update_request(&pr->thermal_req, max_freq);
- if (ret < 0) {
- pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
- pr->id, ret);
- }
}
return 0;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v5 3/6] cpufreq: intel_pstate: Use scope-based cleanup helper
2025-09-05 13:24 [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 1/6] arm64: topology: Use scope-based cleanup helper Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 2/6] ACPI: processor: thermal: " Zihuan Zhang
@ 2025-09-05 13:24 ` Zihuan Zhang
2025-09-05 13:31 ` Rafael J. Wysocki
2025-09-05 13:24 ` [PATCH v5 4/6] PM / devfreq: " Zihuan Zhang
` (3 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: Zihuan Zhang @ 2025-09-05 13:24 UTC (permalink / raw)
To: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy
Cc: Ben Horgan, zhenglifeng, Zhang Rui, Len Brown, Lukasz Luba,
Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
Yicong Yang, linux-pm, linux-acpi, linuxppc-dev, linux-arm-kernel,
intel-gfx, dri-devel, imx, linux-omap, 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>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
---
drivers/cpufreq/intel_pstate.c | 59 +++++++++++++++++++---------------
1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index f366d35c5840..0b54e08f9447 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -1502,9 +1502,8 @@ static void __intel_pstate_update_max_freq(struct cpufreq_policy *policy,
static bool intel_pstate_update_max_freq(struct cpudata *cpudata)
{
- struct cpufreq_policy *policy __free(put_cpufreq_policy);
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpudata->cpu);
- policy = cpufreq_cpu_get(cpudata->cpu);
if (!policy)
return false;
@@ -1695,41 +1694,49 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
return count;
}
-static void update_qos_request(enum freq_qos_req_type type)
+static bool intel_pstate_cpufreq_update_limits(int cpu, enum freq_qos_req_type type)
{
struct freq_qos_request *req;
- struct cpufreq_policy *policy;
- int i;
+ unsigned int freq, perf_pct;
+ struct cpudata *data = all_cpu_data[cpu];
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
- for_each_possible_cpu(i) {
- struct cpudata *cpu = all_cpu_data[i];
- unsigned int freq, perf_pct;
+ if (!policy)
+ return false;
- policy = cpufreq_cpu_get(i);
- if (!policy)
- continue;
+ req = policy->driver_data;
- req = policy->driver_data;
- cpufreq_cpu_put(policy);
+ if (!req)
+ return false;
- if (!req)
- continue;
+ if (hwp_active)
+ intel_pstate_get_hwp_cap(data);
- if (hwp_active)
- intel_pstate_get_hwp_cap(cpu);
+ if (type == FREQ_QOS_MIN) {
+ perf_pct = global.min_perf_pct;
+ } else {
+ req++;
+ perf_pct = global.max_perf_pct;
+ }
- if (type == FREQ_QOS_MIN) {
- perf_pct = global.min_perf_pct;
- } else {
- req++;
- perf_pct = global.max_perf_pct;
- }
+ freq = DIV_ROUND_UP(data->pstate.turbo_freq * perf_pct, 100);
- freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * perf_pct, 100);
+ if (freq_qos_update_request(req, freq) < 0)
+ pr_warn("Failed to update freq constraint: CPU%d\n", cpu);
- if (freq_qos_update_request(req, freq) < 0)
- pr_warn("Failed to update freq constraint: CPU%d\n", i);
+ return true;
+}
+
+
+static void update_qos_request(enum freq_qos_req_type type)
+{
+ int i;
+
+ for_each_possible_cpu(i) {
+ if (!intel_pstate_cpufreq_update_limits(i, type))
+ continue;
}
+
}
static ssize_t store_max_perf_pct(struct kobject *a, struct kobj_attribute *b,
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v5 4/6] PM / devfreq: Use scope-based cleanup helper
2025-09-05 13:24 [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
` (2 preceding siblings ...)
2025-09-05 13:24 ` [PATCH v5 3/6] cpufreq: intel_pstate: " Zihuan Zhang
@ 2025-09-05 13:24 ` Zihuan Zhang
2025-09-05 19:39 ` Rafael J. Wysocki
2025-09-05 13:24 ` [PATCH v5 5/6] drm/i915: " Zihuan Zhang
` (2 subsequent siblings)
6 siblings, 1 reply; 17+ messages in thread
From: Zihuan Zhang @ 2025-09-05 13:24 UTC (permalink / raw)
To: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy
Cc: Ben Horgan, zhenglifeng, Zhang Rui, Len Brown, Lukasz Luba,
Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
Yicong Yang, linux-pm, linux-acpi, linuxppc-dev, linux-arm-kernel,
intel-gfx, dri-devel, imx, linux-omap, 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 | 60 +++++++++++-------------------
1 file changed, 22 insertions(+), 38 deletions(-)
diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c
index 953cf9a1e9f7..5afaea39377e 100644
--- a/drivers/devfreq/governor_passive.c
+++ b/drivers/devfreq/governor_passive.c
@@ -80,24 +80,23 @@ 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) {
- policy = cpufreq_cpu_get(cpu);
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) =
+ cpufreq_cpu_get(cpu);
+
if (!policy) {
ret = -EINVAL;
continue;
}
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 +105,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 +119,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;
@@ -255,8 +252,6 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
= (struct devfreq_passive_data *)devfreq->data;
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,37 +268,34 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
}
for_each_possible_cpu(cpu) {
- policy = cpufreq_cpu_get(cpu);
- if (!policy) {
- ret = -EPROBE_DEFER;
- goto err;
- }
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) =
+ cpufreq_cpu_get(cpu);
- parent_cpu_data = get_parent_cpu_data(p_data, policy);
- if (parent_cpu_data) {
- cpufreq_cpu_put(policy);
+ if (!policy)
+ return -EPROBE_DEFER;
+
+ struct devfreq_cpu_data *initial_parent_cpu_data =
+ get_parent_cpu_data(p_data, policy);
+
+ if (initial_parent_cpu_data)
continue;
- }
- parent_cpu_data = kzalloc(sizeof(*parent_cpu_data),
- GFP_KERNEL);
- if (!parent_cpu_data) {
- ret = -ENOMEM;
- goto err_put_policy;
- }
+ struct devfreq_cpu_data *parent_cpu_data __free(kfree) =
+ kzalloc(sizeof(*parent_cpu_data), GFP_KERNEL);
+
+ if (!parent_cpu_data)
+ return -ENOMEM;
cpu_dev = get_cpu_device(cpu);
if (!cpu_dev) {
dev_err(dev, "failed to get cpu device\n");
- ret = -ENODEV;
- goto err_free_cpu_data;
+ return -ENODEV;
}
opp_table = dev_pm_opp_get_opp_table(cpu_dev);
if (IS_ERR(opp_table)) {
dev_err(dev, "failed to get opp_table of cpu%d\n", cpu);
- ret = PTR_ERR(opp_table);
- goto err_free_cpu_data;
+ return PTR_ERR(opp_table);
}
parent_cpu_data->dev = cpu_dev;
@@ -313,8 +305,8 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
parent_cpu_data->min_freq = policy->cpuinfo.min_freq;
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);
+ list_add_tail(&(no_free_ptr(parent_cpu_data)->node,
+ &p_data->cpu_data_list);
}
mutex_lock(&devfreq->lock);
@@ -324,14 +316,6 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
dev_err(dev, "failed to update the frequency\n");
return ret;
-
-err_free_cpu_data:
- kfree(parent_cpu_data);
-err_put_policy:
- cpufreq_cpu_put(policy);
-err:
-
- return ret;
}
static int devfreq_passive_notifier_call(struct notifier_block *nb,
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v5 5/6] drm/i915: Use scope-based cleanup helper
2025-09-05 13:24 [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
` (3 preceding siblings ...)
2025-09-05 13:24 ` [PATCH v5 4/6] PM / devfreq: " Zihuan Zhang
@ 2025-09-05 13:24 ` Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 6/6] PM: EM: " Zihuan Zhang
2025-09-05 17:49 ` [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Borislav Petkov
6 siblings, 0 replies; 17+ messages in thread
From: Zihuan Zhang @ 2025-09-05 13:24 UTC (permalink / raw)
To: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy
Cc: Ben Horgan, zhenglifeng, Zhang Rui, Len Brown, Lukasz Luba,
Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
Yicong Yang, linux-pm, linux-acpi, linuxppc-dev, linux-arm-kernel,
intel-gfx, dri-devel, imx, linux-omap, 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>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
---
drivers/gpu/drm/i915/gt/intel_llc.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/i915/gt/intel_llc.c b/drivers/gpu/drm/i915/gt/intel_llc.c
index 1d19c073ba2e..f15e4c0fa54b 100644
--- a/drivers/gpu/drm/i915/gt/intel_llc.c
+++ b/drivers/gpu/drm/i915/gt/intel_llc.c
@@ -29,13 +29,11 @@ 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) = cpufreq_cpu_get(0);
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] 17+ messages in thread
* [PATCH v5 6/6] PM: EM: Use scope-based cleanup helper
2025-09-05 13:24 [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
` (4 preceding siblings ...)
2025-09-05 13:24 ` [PATCH v5 5/6] drm/i915: " Zihuan Zhang
@ 2025-09-05 13:24 ` Zihuan Zhang
2025-09-05 19:46 ` Rafael J. Wysocki
2025-09-05 17:49 ` [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Borislav Petkov
6 siblings, 1 reply; 17+ messages in thread
From: Zihuan Zhang @ 2025-09-05 13:24 UTC (permalink / raw)
To: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy
Cc: Ben Horgan, zhenglifeng, Zhang Rui, Len Brown, Lukasz Luba,
Pengutronix Kernel Team, Beata Michalska, Fabio Estevam,
Pavel Machek, Sumit Gupta, Prasanna Kumar T S M, Sudeep Holla,
Yicong Yang, linux-pm, linux-acpi, linuxppc-dev, linux-arm-kernel,
intel-gfx, dri-devel, imx, linux-omap, 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 | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
index ea7995a25780..5ec63b3e7d85 100644
--- a/kernel/power/energy_model.c
+++ b/kernel/power/energy_model.c
@@ -451,7 +451,6 @@ static void
em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
{
struct em_perf_domain *pd = dev->em_pd;
- struct cpufreq_policy *policy;
int found = 0;
int i, cpu;
@@ -465,7 +464,7 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
return;
}
- policy = cpufreq_cpu_get(cpu);
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
if (!policy) {
dev_warn(dev, "EM: Access to CPUFreq policy failed\n");
return;
@@ -479,8 +478,6 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
found++;
}
- cpufreq_cpu_put(policy);
-
if (!found)
return;
@@ -787,21 +784,19 @@ static void em_check_capacity_update(void)
/* Check if CPUs capacity has changed than update EM */
for_each_possible_cpu(cpu) {
- struct cpufreq_policy *policy;
struct em_perf_domain *pd;
struct device *dev;
if (cpumask_test_cpu(cpu, cpu_done_mask))
continue;
- policy = cpufreq_cpu_get(cpu);
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
if (!policy) {
pr_debug("Accessing cpu%d policy failed\n", cpu);
schedule_delayed_work(&em_update_work,
msecs_to_jiffies(1000));
break;
}
- cpufreq_cpu_put(policy);
dev = get_cpu_device(cpu);
pd = em_pd_get(dev);
--
2.25.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v5 3/6] cpufreq: intel_pstate: Use scope-based cleanup helper
2025-09-05 13:24 ` [PATCH v5 3/6] cpufreq: intel_pstate: " Zihuan Zhang
@ 2025-09-05 13:31 ` Rafael J. Wysocki
0 siblings, 0 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2025-09-05 13:31 UTC (permalink / raw)
To: Zihuan Zhang
Cc: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng,
Zhang Rui, Len Brown, Lukasz Luba, Pengutronix Kernel Team,
Beata Michalska, Fabio Estevam, Pavel Machek, Sumit Gupta,
Prasanna Kumar T S M, Sudeep Holla, Yicong Yang, linux-pm,
linux-acpi, linuxppc-dev, linux-arm-kernel, intel-gfx, dri-devel,
imx, linux-omap, linux-kernel
On Fri, Sep 5, 2025 at 3:24 PM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
> Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy)
> annotation for policy references. This reduces the risk of reference
> counting mistakes and aligns the code with the latest kernel style.
>
> No functional change intended.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
No, sorry. I've already said that this isn't going to work:
https://lore.kernel.org/linux-pm/CAJZ5v0gN1T5woSF0tO=TbAh+2-sWzxFjWyDbB7wG2TFCOU01iQ@mail.gmail.com/
so why are you resending it?
And making changes to it in the process without saying what they are?
Please stop adding confusion.
> ---
> drivers/cpufreq/intel_pstate.c | 59 +++++++++++++++++++---------------
> 1 file changed, 33 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> index f366d35c5840..0b54e08f9447 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -1502,9 +1502,8 @@ static void __intel_pstate_update_max_freq(struct cpufreq_policy *policy,
>
> static bool intel_pstate_update_max_freq(struct cpudata *cpudata)
> {
> - struct cpufreq_policy *policy __free(put_cpufreq_policy);
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpudata->cpu);
>
> - policy = cpufreq_cpu_get(cpudata->cpu);
> if (!policy)
> return false;
>
> @@ -1695,41 +1694,49 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
> return count;
> }
>
> -static void update_qos_request(enum freq_qos_req_type type)
> +static bool intel_pstate_cpufreq_update_limits(int cpu, enum freq_qos_req_type type)
> {
> struct freq_qos_request *req;
> - struct cpufreq_policy *policy;
> - int i;
> + unsigned int freq, perf_pct;
> + struct cpudata *data = all_cpu_data[cpu];
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
>
> - for_each_possible_cpu(i) {
> - struct cpudata *cpu = all_cpu_data[i];
> - unsigned int freq, perf_pct;
> + if (!policy)
> + return false;
>
> - policy = cpufreq_cpu_get(i);
> - if (!policy)
> - continue;
> + req = policy->driver_data;
>
> - req = policy->driver_data;
> - cpufreq_cpu_put(policy);
> + if (!req)
> + return false;
>
> - if (!req)
> - continue;
> + if (hwp_active)
> + intel_pstate_get_hwp_cap(data);
>
> - if (hwp_active)
> - intel_pstate_get_hwp_cap(cpu);
> + if (type == FREQ_QOS_MIN) {
> + perf_pct = global.min_perf_pct;
> + } else {
> + req++;
> + perf_pct = global.max_perf_pct;
> + }
>
> - if (type == FREQ_QOS_MIN) {
> - perf_pct = global.min_perf_pct;
> - } else {
> - req++;
> - perf_pct = global.max_perf_pct;
> - }
> + freq = DIV_ROUND_UP(data->pstate.turbo_freq * perf_pct, 100);
>
> - freq = DIV_ROUND_UP(cpu->pstate.turbo_freq * perf_pct, 100);
> + if (freq_qos_update_request(req, freq) < 0)
> + pr_warn("Failed to update freq constraint: CPU%d\n", cpu);
>
> - if (freq_qos_update_request(req, freq) < 0)
> - pr_warn("Failed to update freq constraint: CPU%d\n", i);
> + return true;
> +}
> +
> +
> +static void update_qos_request(enum freq_qos_req_type type)
> +{
> + int i;
> +
> + for_each_possible_cpu(i) {
> + if (!intel_pstate_cpufreq_update_limits(i, type))
> + continue;
> }
> +
> }
>
> static ssize_t store_max_perf_pct(struct kobject *a, struct kobj_attribute *b,
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references
2025-09-05 13:24 [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
` (5 preceding siblings ...)
2025-09-05 13:24 ` [PATCH v5 6/6] PM: EM: " Zihuan Zhang
@ 2025-09-05 17:49 ` Borislav Petkov
2025-09-08 9:12 ` Zihuan Zhang
6 siblings, 1 reply; 17+ messages in thread
From: Borislav Petkov @ 2025-09-05 17:49 UTC (permalink / raw)
To: Zihuan Zhang
Cc: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Dave Hansen, Srinivas Pandruvada,
Michael Ellerman, Krzysztof Kozlowski, Alim Akhtar,
Thierry Reding, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng, Zhang Rui,
Len Brown, Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
Sudeep Holla, Yicong Yang, linux-pm, linux-acpi, linuxppc-dev,
linux-arm-kernel, intel-gfx, dri-devel, imx, linux-omap,
linux-kernel
On Fri, Sep 05, 2025 at 09:24:07PM +0800, Zihuan Zhang wrote:
> 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.
Sep 01 Zihuan Zhang ( :8.6K|) [PATCH v3 00/12] cpufreq: use __free() for all cpufreq_cpu_get() references
Sep 03 Zihuan Zhang ( : 65|) [PATCH v4 00/10] cpufreq: use __free() for all cpufreq_cpu_get() references
Sep 05 Zihuan Zhang ( :8.3K|) [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references
Please stop the spamming. While waiting, go read how this kernel process thing
works:
From: Documentation/process/submitting-patches.rst
Don't get discouraged - or impatient
------------------------------------
After you have submitted your change, be patient and wait. Reviewers are
busy people and may not get to your patch right away.
Once upon a time, patches used to disappear into the void without comment,
but the development process works more smoothly than that now. You should
receive comments within a week or so; if that does not happen, make sure
that you have sent your patches to the right place. Wait for a minimum of
one week before resubmitting or pinging reviewers - possibly longer during
busy times like merge windows.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v5 4/6] PM / devfreq: Use scope-based cleanup helper
2025-09-05 13:24 ` [PATCH v5 4/6] PM / devfreq: " Zihuan Zhang
@ 2025-09-05 19:39 ` Rafael J. Wysocki
0 siblings, 0 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2025-09-05 19:39 UTC (permalink / raw)
To: Zihuan Zhang
Cc: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng,
Zhang Rui, Len Brown, Lukasz Luba, Pengutronix Kernel Team,
Beata Michalska, Fabio Estevam, Pavel Machek, Sumit Gupta,
Prasanna Kumar T S M, Sudeep Holla, Yicong Yang, linux-pm,
linux-acpi, linuxppc-dev, linux-arm-kernel, intel-gfx, dri-devel,
imx, linux-omap, linux-kernel
On Fri, Sep 5, 2025 at 3:25 PM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
> Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy)
> annotation for policy references. This reduces the risk of reference
> counting mistakes and aligns the code with the latest kernel style.
>
> No functional change intended.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> ---
> drivers/devfreq/governor_passive.c | 60 +++++++++++-------------------
> 1 file changed, 22 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c
> index 953cf9a1e9f7..5afaea39377e 100644
> --- a/drivers/devfreq/governor_passive.c
> +++ b/drivers/devfreq/governor_passive.c
> @@ -80,24 +80,23 @@ 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) {
I'd rather move the code in this loop to a separate function in the
first place and then do a __free()-based simplification of it. I'd
suggest doing each step in a separate patch to avoid mistakes.
> - policy = cpufreq_cpu_get(cpu);
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) =
> + cpufreq_cpu_get(cpu);
> +
> if (!policy) {
> ret = -EINVAL;
> continue;
> }
>
> 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 +105,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 +119,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;
> @@ -255,8 +252,6 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
> = (struct devfreq_passive_data *)devfreq->data;
> 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,37 +268,34 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
> }
>
> for_each_possible_cpu(cpu) {
And analogously here. I'd use separate two patches for updating this code.
> - policy = cpufreq_cpu_get(cpu);
> - if (!policy) {
> - ret = -EPROBE_DEFER;
> - goto err;
> - }
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) =
> + cpufreq_cpu_get(cpu);
>
> - parent_cpu_data = get_parent_cpu_data(p_data, policy);
> - if (parent_cpu_data) {
> - cpufreq_cpu_put(policy);
> + if (!policy)
> + return -EPROBE_DEFER;
> +
> + struct devfreq_cpu_data *initial_parent_cpu_data =
> + get_parent_cpu_data(p_data, policy);
> +
> + if (initial_parent_cpu_data)
> continue;
> - }
>
> - parent_cpu_data = kzalloc(sizeof(*parent_cpu_data),
> - GFP_KERNEL);
> - if (!parent_cpu_data) {
> - ret = -ENOMEM;
> - goto err_put_policy;
> - }
> + struct devfreq_cpu_data *parent_cpu_data __free(kfree) =
> + kzalloc(sizeof(*parent_cpu_data), GFP_KERNEL);
> +
> + if (!parent_cpu_data)
> + return -ENOMEM;
>
> cpu_dev = get_cpu_device(cpu);
> if (!cpu_dev) {
> dev_err(dev, "failed to get cpu device\n");
> - ret = -ENODEV;
> - goto err_free_cpu_data;
> + return -ENODEV;
> }
>
> opp_table = dev_pm_opp_get_opp_table(cpu_dev);
> if (IS_ERR(opp_table)) {
> dev_err(dev, "failed to get opp_table of cpu%d\n", cpu);
> - ret = PTR_ERR(opp_table);
> - goto err_free_cpu_data;
> + return PTR_ERR(opp_table);
> }
>
> parent_cpu_data->dev = cpu_dev;
> @@ -313,8 +305,8 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
> parent_cpu_data->min_freq = policy->cpuinfo.min_freq;
> 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);
> + list_add_tail(&(no_free_ptr(parent_cpu_data)->node,
> + &p_data->cpu_data_list);
> }
>
> mutex_lock(&devfreq->lock);
> @@ -324,14 +316,6 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
> dev_err(dev, "failed to update the frequency\n");
>
> return ret;
> -
> -err_free_cpu_data:
> - kfree(parent_cpu_data);
> -err_put_policy:
> - cpufreq_cpu_put(policy);
> -err:
> -
> - return ret;
> }
>
> static int devfreq_passive_notifier_call(struct notifier_block *nb,
> --
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v5 6/6] PM: EM: Use scope-based cleanup helper
2025-09-05 13:24 ` [PATCH v5 6/6] PM: EM: " Zihuan Zhang
@ 2025-09-05 19:46 ` Rafael J. Wysocki
0 siblings, 0 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2025-09-05 19:46 UTC (permalink / raw)
To: Zihuan Zhang
Cc: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng,
Zhang Rui, Len Brown, Lukasz Luba, Pengutronix Kernel Team,
Beata Michalska, Fabio Estevam, Pavel Machek, Sumit Gupta,
Prasanna Kumar T S M, Sudeep Holla, Yicong Yang, linux-pm,
linux-acpi, linuxppc-dev, linux-arm-kernel, intel-gfx, dri-devel,
imx, linux-omap, linux-kernel
On Fri, Sep 5, 2025 at 3:25 PM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
> Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy)
> annotation for policy references. This reduces the risk of reference
> counting mistakes and aligns the code with the latest kernel style.
>
> No functional change intended.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> ---
> kernel/power/energy_model.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
> index ea7995a25780..5ec63b3e7d85 100644
> --- a/kernel/power/energy_model.c
> +++ b/kernel/power/energy_model.c
> @@ -451,7 +451,6 @@ static void
> em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
> {
> struct em_perf_domain *pd = dev->em_pd;
> - struct cpufreq_policy *policy;
> int found = 0;
> int i, cpu;
>
> @@ -465,7 +464,7 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
> return;
> }
>
> - policy = cpufreq_cpu_get(cpu);
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> if (!policy) {
> dev_warn(dev, "EM: Access to CPUFreq policy failed\n");
> return;
> @@ -479,8 +478,6 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table)
> found++;
> }
>
> - cpufreq_cpu_put(policy);
> -
> if (!found)
> return;
>
The above changes are fine now and can be a separate patch.
> @@ -787,21 +784,19 @@ static void em_check_capacity_update(void)
>
> /* Check if CPUs capacity has changed than update EM */
> for_each_possible_cpu(cpu) {
But I'd prefer the code in this loop to be moved into a separate
function, in a separate patch, before the __free()-based
simplification of it.
> - struct cpufreq_policy *policy;
> struct em_perf_domain *pd;
> struct device *dev;
>
> if (cpumask_test_cpu(cpu, cpu_done_mask))
> continue;
>
> - policy = cpufreq_cpu_get(cpu);
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> if (!policy) {
> pr_debug("Accessing cpu%d policy failed\n", cpu);
> schedule_delayed_work(&em_update_work,
> msecs_to_jiffies(1000));
> break;
> }
> - cpufreq_cpu_put(policy);
>
> dev = get_cpu_device(cpu);
> pd = em_pd_get(dev);
> --
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v5 2/6] ACPI: processor: thermal: Use scope-based cleanup helper
2025-09-05 13:24 ` [PATCH v5 2/6] ACPI: processor: thermal: " Zihuan Zhang
@ 2025-09-05 20:17 ` Rafael J. Wysocki
2025-09-08 9:16 ` Zihuan Zhang
2025-09-08 17:55 ` Rafael J. Wysocki
1 sibling, 1 reply; 17+ messages in thread
From: Rafael J. Wysocki @ 2025-09-05 20:17 UTC (permalink / raw)
To: Zihuan Zhang
Cc: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng,
Zhang Rui, Len Brown, Lukasz Luba, Pengutronix Kernel Team,
Beata Michalska, Fabio Estevam, Pavel Machek, Sumit Gupta,
Prasanna Kumar T S M, Sudeep Holla, Yicong Yang, linux-pm,
linux-acpi, linuxppc-dev, linux-arm-kernel, intel-gfx, dri-devel,
imx, linux-omap, linux-kernel
On Fri, Sep 5, 2025 at 3:24 PM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
> Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy)
> annotation for policy references. This reduces the risk of reference
> counting mistakes and aligns the code with the latest kernel style.
>
> No functional change intended.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> ---
> drivers/acpi/processor_thermal.c | 52 +++++++++++++++++---------------
> 1 file changed, 27 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
> index 1219adb11ab9..460713d1414a 100644
> --- a/drivers/acpi/processor_thermal.c
> +++ b/drivers/acpi/processor_thermal.c
> @@ -62,19 +62,14 @@ static int phys_package_first_cpu(int cpu)
> return 0;
> }
>
> -static int cpu_has_cpufreq(unsigned int cpu)
> +static bool cpu_has_cpufreq(unsigned int cpu)
> {
> - struct cpufreq_policy *policy;
> -
> if (!acpi_processor_cpufreq_init)
> return 0;
>
> - policy = cpufreq_cpu_get(cpu);
> - if (policy) {
> - cpufreq_cpu_put(policy);
> - return 1;
> - }
> - return 0;
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> +
> + return policy != NULL;
> }
>
> static int cpufreq_get_max_state(unsigned int cpu)
The changes above are fine and can be sent as a separate patch.
> @@ -93,12 +88,31 @@ static int cpufreq_get_cur_state(unsigned int cpu)
> return reduction_step(cpu);
> }
>
> +static bool cpufreq_update_thermal_limit(unsigned int cpu, struct acpi_processor *pr)
> +{
> + unsigned long max_freq;
> + int ret;
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> +
> + if (!policy)
> + return false;
> +
> + max_freq = (policy->cpuinfo.max_freq *
> + (100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100;
> +
> + ret = freq_qos_update_request(&pr->thermal_req, max_freq);
> + if (ret < 0) {
> + pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
> + pr->id, ret);
> + }
But this silently fixes a bug in the original code which needs to be
documented with a Fixes: tag (and it would be better to fix the bug
separately before the using the __free()-based cleanup TBH) and
introduces some whitespace breakage.
> +
> + return true;
> +}
> +
> static int cpufreq_set_cur_state(unsigned int cpu, int state)
> {
> - struct cpufreq_policy *policy;
> struct acpi_processor *pr;
> - unsigned long max_freq;
> - int i, ret;
> + int i;
>
> if (!cpu_has_cpufreq(cpu))
> return 0;
> @@ -120,20 +134,8 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
> if (unlikely(!freq_qos_request_active(&pr->thermal_req)))
> continue;
>
> - policy = cpufreq_cpu_get(i);
> - if (!policy)
> + if (!cpufreq_update_thermal_limit(i, pr))
> return -EINVAL;
> -
> - max_freq = (policy->cpuinfo.max_freq *
> - (100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100;
> -
> - cpufreq_cpu_put(policy);
> -
> - ret = freq_qos_update_request(&pr->thermal_req, max_freq);
> - if (ret < 0) {
> - pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
> - pr->id, ret);
> - }
> }
> return 0;
> }
> --
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references
2025-09-05 17:49 ` [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Borislav Petkov
@ 2025-09-08 9:12 ` Zihuan Zhang
2025-09-08 9:24 ` Borislav Petkov
0 siblings, 1 reply; 17+ messages in thread
From: Zihuan Zhang @ 2025-09-08 9:12 UTC (permalink / raw)
To: Borislav Petkov
Cc: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Dave Hansen, Srinivas Pandruvada,
Michael Ellerman, Krzysztof Kozlowski, Alim Akhtar,
Thierry Reding, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng, Zhang Rui,
Len Brown, Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
Sudeep Holla, Yicong Yang, linux-pm, linux-acpi, linuxppc-dev,
linux-arm-kernel, intel-gfx, dri-devel, imx, linux-omap,
linux-kernel
在 2025/9/6 01:49, Borislav Petkov 写道:
> On Fri, Sep 05, 2025 at 09:24:07PM +0800, Zihuan Zhang wrote:
>> 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.
> Sep 01 Zihuan Zhang ( :8.6K|) [PATCH v3 00/12] cpufreq: use __free() for all cpufreq_cpu_get() references
> Sep 03 Zihuan Zhang ( : 65|) [PATCH v4 00/10] cpufreq: use __free() for all cpufreq_cpu_get() references
> Sep 05 Zihuan Zhang ( :8.3K|) [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references
>
> Please stop the spamming. While waiting, go read how this kernel process thing
> works:
>
> From: Documentation/process/submitting-patches.rst
>
> Don't get discouraged - or impatient
> ------------------------------------
>
> After you have submitted your change, be patient and wait. Reviewers are
> busy people and may not get to your patch right away.
>
> Once upon a time, patches used to disappear into the void without comment,
> but the development process works more smoothly than that now. You should
> receive comments within a week or so; if that does not happen, make sure
> that you have sent your patches to the right place. Wait for a minimum of
> one week before resubmitting or pinging reviewers - possibly longer during
> busy times like merge windows.
Sorry for the noise. I’ll split the patchset and avoid CC’ing
unnecessary people in the future.
Thanks for the reminder!
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v5 2/6] ACPI: processor: thermal: Use scope-based cleanup helper
2025-09-05 20:17 ` Rafael J. Wysocki
@ 2025-09-08 9:16 ` Zihuan Zhang
2025-09-08 17:44 ` Rafael J. Wysocki
0 siblings, 1 reply; 17+ messages in thread
From: Zihuan Zhang @ 2025-09-08 9:16 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Viresh Kumar, Jonathan Cameron, Catalin Marinas, Will Deacon,
Borislav Petkov, Dave Hansen, Srinivas Pandruvada,
Michael Ellerman, Krzysztof Kozlowski, Alim Akhtar,
Thierry Reding, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng, Zhang Rui,
Len Brown, Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
Sudeep Holla, Yicong Yang, linux-pm, linux-acpi, linuxppc-dev,
linux-arm-kernel, intel-gfx, dri-devel, imx, linux-omap,
linux-kernel
在 2025/9/6 04:17, Rafael J. Wysocki 写道:
> On Fri, Sep 5, 2025 at 3:24 PM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>> Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy)
>> annotation for policy references. This reduces the risk of reference
>> counting mistakes and aligns the code with the latest kernel style.
>>
>> No functional change intended.
>>
>> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
>> ---
>> drivers/acpi/processor_thermal.c | 52 +++++++++++++++++---------------
>> 1 file changed, 27 insertions(+), 25 deletions(-)
>>
>> diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
>> index 1219adb11ab9..460713d1414a 100644
>> --- a/drivers/acpi/processor_thermal.c
>> +++ b/drivers/acpi/processor_thermal.c
>> @@ -62,19 +62,14 @@ static int phys_package_first_cpu(int cpu)
>> return 0;
>> }
>>
>> -static int cpu_has_cpufreq(unsigned int cpu)
>> +static bool cpu_has_cpufreq(unsigned int cpu)
>> {
>> - struct cpufreq_policy *policy;
>> -
>> if (!acpi_processor_cpufreq_init)
>> return 0;
>>
>> - policy = cpufreq_cpu_get(cpu);
>> - if (policy) {
>> - cpufreq_cpu_put(policy);
>> - return 1;
>> - }
>> - return 0;
>> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
>> +
>> + return policy != NULL;
>> }
>>
>> static int cpufreq_get_max_state(unsigned int cpu)
> The changes above are fine and can be sent as a separate patch.
>
>> @@ -93,12 +88,31 @@ static int cpufreq_get_cur_state(unsigned int cpu)
>> return reduction_step(cpu);
>> }
>>
>> +static bool cpufreq_update_thermal_limit(unsigned int cpu, struct acpi_processor *pr)
>> +{
>> + unsigned long max_freq;
>> + int ret;
>> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
>> +
>> + if (!policy)
>> + return false;
>> +
>> + max_freq = (policy->cpuinfo.max_freq *
>> + (100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100;
>> +
>> + ret = freq_qos_update_request(&pr->thermal_req, max_freq);
>> + if (ret < 0) {
>> + pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
>> + pr->id, ret);
>> + }
> But this silently fixes a bug in the original code which needs to be
> documented with a Fixes: tag (and it would be better to fix the bug
> separately before the using the __free()-based cleanup TBH) and
> introduces some whitespace breakage.
Thanks!
I’ll follow your advice and handle the Fixes tag and whitespace issues.
>> +
>> + return true;
>> +}
>> +
>> static int cpufreq_set_cur_state(unsigned int cpu, int state)
>> {
>> - struct cpufreq_policy *policy;
>> struct acpi_processor *pr;
>> - unsigned long max_freq;
>> - int i, ret;
>> + int i;
>>
>> if (!cpu_has_cpufreq(cpu))
>> return 0;
>> @@ -120,20 +134,8 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
>> if (unlikely(!freq_qos_request_active(&pr->thermal_req)))
>> continue;
>>
>> - policy = cpufreq_cpu_get(i);
>> - if (!policy)
>> + if (!cpufreq_update_thermal_limit(i, pr))
>> return -EINVAL;
>> -
>> - max_freq = (policy->cpuinfo.max_freq *
>> - (100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100;
>> -
>> - cpufreq_cpu_put(policy);
>> -
>> - ret = freq_qos_update_request(&pr->thermal_req, max_freq);
>> - if (ret < 0) {
>> - pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
>> - pr->id, ret);
>> - }
>> }
>> return 0;
>> }
>> --
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references
2025-09-08 9:12 ` Zihuan Zhang
@ 2025-09-08 9:24 ` Borislav Petkov
0 siblings, 0 replies; 17+ messages in thread
From: Borislav Petkov @ 2025-09-08 9:24 UTC (permalink / raw)
To: Zihuan Zhang
Cc: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Dave Hansen, Srinivas Pandruvada,
Michael Ellerman, Krzysztof Kozlowski, Alim Akhtar,
Thierry Reding, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin, David Airlie,
Simona Vetter, Daniel Lezcano, Sascha Hauer, Shawn Guo,
Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng, Zhang Rui,
Len Brown, Lukasz Luba, Pengutronix Kernel Team, Beata Michalska,
Fabio Estevam, Pavel Machek, Sumit Gupta, Prasanna Kumar T S M,
Sudeep Holla, Yicong Yang, linux-pm, linux-acpi, linuxppc-dev,
linux-arm-kernel, intel-gfx, dri-devel, imx, linux-omap,
linux-kernel
On Mon, Sep 08, 2025 at 05:12:37PM +0800, Zihuan Zhang wrote:
> > From: Documentation/process/submitting-patches.rst
> >
> > Don't get discouraged - or impatient
> > ------------------------------------
> >
> > After you have submitted your change, be patient and wait. Reviewers are
> > busy people and may not get to your patch right away.
> >
> > Once upon a time, patches used to disappear into the void without comment,
> > but the development process works more smoothly than that now. You should
> > receive comments within a week or so; if that does not happen, make sure
> > that you have sent your patches to the right place. Wait for a minimum of
> > one week before resubmitting or pinging reviewers - possibly longer during
> > busy times like merge windows.
> Sorry for the noise. I’ll split the patchset and avoid CC’ing unnecessary
> people in the future.
I don't think you read what I sent you. Lemme spell it out: you're supposed to
*wait* to gather review feedback, at least a week. While waiting,
*incorporate* or *address* all that feedback and *then* send a new set.
If you keep spamming people like that, you'll accomplish the opposite of what
you're trying to do.
And while waiting you can read our documentation on the community process so
that you know what to do in the future.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v5 2/6] ACPI: processor: thermal: Use scope-based cleanup helper
2025-09-08 9:16 ` Zihuan Zhang
@ 2025-09-08 17:44 ` Rafael J. Wysocki
0 siblings, 0 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2025-09-08 17:44 UTC (permalink / raw)
To: Zihuan Zhang
Cc: Rafael J. Wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng,
Zhang Rui, Len Brown, Lukasz Luba, Pengutronix Kernel Team,
Beata Michalska, Fabio Estevam, Pavel Machek, Sumit Gupta,
Prasanna Kumar T S M, Sudeep Holla, Yicong Yang, linux-pm,
linux-acpi, linuxppc-dev, linux-arm-kernel, intel-gfx, dri-devel,
imx, linux-omap, linux-kernel
On Mon, Sep 8, 2025 at 11:16 AM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
>
> 在 2025/9/6 04:17, Rafael J. Wysocki 写道:
> > On Fri, Sep 5, 2025 at 3:24 PM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
> >> Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy)
> >> annotation for policy references. This reduces the risk of reference
> >> counting mistakes and aligns the code with the latest kernel style.
> >>
> >> No functional change intended.
> >>
> >> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> >> ---
> >> drivers/acpi/processor_thermal.c | 52 +++++++++++++++++---------------
> >> 1 file changed, 27 insertions(+), 25 deletions(-)
> >>
> >> diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
> >> index 1219adb11ab9..460713d1414a 100644
> >> --- a/drivers/acpi/processor_thermal.c
> >> +++ b/drivers/acpi/processor_thermal.c
> >> @@ -62,19 +62,14 @@ static int phys_package_first_cpu(int cpu)
> >> return 0;
> >> }
> >>
> >> -static int cpu_has_cpufreq(unsigned int cpu)
> >> +static bool cpu_has_cpufreq(unsigned int cpu)
> >> {
> >> - struct cpufreq_policy *policy;
> >> -
> >> if (!acpi_processor_cpufreq_init)
> >> return 0;
> >>
> >> - policy = cpufreq_cpu_get(cpu);
> >> - if (policy) {
> >> - cpufreq_cpu_put(policy);
> >> - return 1;
> >> - }
> >> - return 0;
> >> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> >> +
> >> + return policy != NULL;
> >> }
> >>
> >> static int cpufreq_get_max_state(unsigned int cpu)
> > The changes above are fine and can be sent as a separate patch.
> >
> >> @@ -93,12 +88,31 @@ static int cpufreq_get_cur_state(unsigned int cpu)
> >> return reduction_step(cpu);
> >> }
> >>
> >> +static bool cpufreq_update_thermal_limit(unsigned int cpu, struct acpi_processor *pr)
> >> +{
> >> + unsigned long max_freq;
> >> + int ret;
> >> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> >> +
> >> + if (!policy)
> >> + return false;
> >> +
> >> + max_freq = (policy->cpuinfo.max_freq *
> >> + (100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100;
> >> +
> >> + ret = freq_qos_update_request(&pr->thermal_req, max_freq);
> >> + if (ret < 0) {
> >> + pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
> >> + pr->id, ret);
> >> + }
> > But this silently fixes a bug in the original code which needs to be
> > documented with a Fixes: tag (and it would be better to fix the bug
> > separately before the using the __free()-based cleanup TBH) and
> > introduces some whitespace breakage.
>
> Thanks!
>
> I’ll follow your advice and handle the Fixes tag and whitespace issues.
Actually, no need to resend.
The current code is correct as it registers and unregisters the freq
QoS request from cpufreq policy notifiers, so the policy is guaranteed
to be there when cpufreq_set_cur_state() runs.
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v5 2/6] ACPI: processor: thermal: Use scope-based cleanup helper
2025-09-05 13:24 ` [PATCH v5 2/6] ACPI: processor: thermal: " Zihuan Zhang
2025-09-05 20:17 ` Rafael J. Wysocki
@ 2025-09-08 17:55 ` Rafael J. Wysocki
1 sibling, 0 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2025-09-08 17:55 UTC (permalink / raw)
To: Zihuan Zhang
Cc: Rafael J . wysocki, Viresh Kumar, Jonathan Cameron,
Catalin Marinas, Will Deacon, Borislav Petkov, Dave Hansen,
Srinivas Pandruvada, Michael Ellerman, Krzysztof Kozlowski,
Alim Akhtar, Thierry Reding, MyungJoo Ham, Kyungmin Park,
Chanwoo Choi, Jani Nikula, Rodrigo Vivi, Tvrtko Ursulin,
David Airlie, Simona Vetter, Daniel Lezcano, Sascha Hauer,
Shawn Guo, Eduardo Valentin, Keerthy, Ben Horgan, zhenglifeng,
Zhang Rui, Len Brown, Lukasz Luba, Pengutronix Kernel Team,
Beata Michalska, Fabio Estevam, Pavel Machek, Sumit Gupta,
Prasanna Kumar T S M, Sudeep Holla, Yicong Yang, linux-pm,
linux-acpi, linuxppc-dev, linux-arm-kernel, intel-gfx, dri-devel,
imx, linux-omap, linux-kernel
On Fri, Sep 5, 2025 at 3:24 PM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
> Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy)
> annotation for policy references. This reduces the risk of reference
> counting mistakes and aligns the code with the latest kernel style.
>
> No functional change intended.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
> ---
> drivers/acpi/processor_thermal.c | 52 +++++++++++++++++---------------
> 1 file changed, 27 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
> index 1219adb11ab9..460713d1414a 100644
> --- a/drivers/acpi/processor_thermal.c
> +++ b/drivers/acpi/processor_thermal.c
> @@ -62,19 +62,14 @@ static int phys_package_first_cpu(int cpu)
> return 0;
> }
>
> -static int cpu_has_cpufreq(unsigned int cpu)
> +static bool cpu_has_cpufreq(unsigned int cpu)
> {
> - struct cpufreq_policy *policy;
> -
> if (!acpi_processor_cpufreq_init)
> return 0;
>
> - policy = cpufreq_cpu_get(cpu);
> - if (policy) {
> - cpufreq_cpu_put(policy);
> - return 1;
> - }
> - return 0;
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> +
> + return policy != NULL;
> }
>
> static int cpufreq_get_max_state(unsigned int cpu)
> @@ -93,12 +88,31 @@ static int cpufreq_get_cur_state(unsigned int cpu)
> return reduction_step(cpu);
> }
>
> +static bool cpufreq_update_thermal_limit(unsigned int cpu, struct acpi_processor *pr)
> +{
> + unsigned long max_freq;
> + int ret;
> + struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);
> +
> + if (!policy)
> + return false;
> +
> + max_freq = (policy->cpuinfo.max_freq *
> + (100 - reduction_step(cpu) * cpufreq_thermal_reduction_pctg)) / 100;
> +
> + ret = freq_qos_update_request(&pr->thermal_req, max_freq);
> + if (ret < 0) {
> + pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
> + pr->id, ret);
> + }
> +
> + return true;
> +}
> +
> static int cpufreq_set_cur_state(unsigned int cpu, int state)
> {
> - struct cpufreq_policy *policy;
> struct acpi_processor *pr;
> - unsigned long max_freq;
> - int i, ret;
> + int i;
>
> if (!cpu_has_cpufreq(cpu))
> return 0;
> @@ -120,20 +134,8 @@ static int cpufreq_set_cur_state(unsigned int cpu, int state)
> if (unlikely(!freq_qos_request_active(&pr->thermal_req)))
> continue;
>
> - policy = cpufreq_cpu_get(i);
> - if (!policy)
> + if (!cpufreq_update_thermal_limit(i, pr))
> return -EINVAL;
> -
> - max_freq = (policy->cpuinfo.max_freq *
> - (100 - reduction_step(i) * cpufreq_thermal_reduction_pctg)) / 100;
> -
> - cpufreq_cpu_put(policy);
> -
> - ret = freq_qos_update_request(&pr->thermal_req, max_freq);
> - if (ret < 0) {
> - pr_warn("Failed to update thermal freq constraint: CPU%d (%d)\n",
> - pr->id, ret);
> - }
> }
> return 0;
> }
> --
Applied as 6.18 material under a new subject, with some minor edits in
the changelog, and with some minor whitespace breakage fixed.
Thanks!
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2025-09-08 17:55 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-05 13:24 [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 1/6] arm64: topology: Use scope-based cleanup helper Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 2/6] ACPI: processor: thermal: " Zihuan Zhang
2025-09-05 20:17 ` Rafael J. Wysocki
2025-09-08 9:16 ` Zihuan Zhang
2025-09-08 17:44 ` Rafael J. Wysocki
2025-09-08 17:55 ` Rafael J. Wysocki
2025-09-05 13:24 ` [PATCH v5 3/6] cpufreq: intel_pstate: " Zihuan Zhang
2025-09-05 13:31 ` Rafael J. Wysocki
2025-09-05 13:24 ` [PATCH v5 4/6] PM / devfreq: " Zihuan Zhang
2025-09-05 19:39 ` Rafael J. Wysocki
2025-09-05 13:24 ` [PATCH v5 5/6] drm/i915: " Zihuan Zhang
2025-09-05 13:24 ` [PATCH v5 6/6] PM: EM: " Zihuan Zhang
2025-09-05 19:46 ` Rafael J. Wysocki
2025-09-05 17:49 ` [PATCH v5 0/6] cpufreq: use __free() for all cpufreq_cpu_get() references Borislav Petkov
2025-09-08 9:12 ` Zihuan Zhang
2025-09-08 9:24 ` Borislav Petkov
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).