[PATCH v3 06/12] PM / devfreq: Use scope-based cleanup helper
From: Zihuan Zhang
Date: Mon Sep 01 2025 - 05:00:01 EST
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@xxxxxxxxxx>
---
drivers/devfreq/governor_passive.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c
index 953cf9a1e9f7..a035cf44bdb8 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;
@@ -256,7 +253,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,23 +269,23 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq)
}
for_each_possible_cpu(cpu) {
- policy = cpufreq_cpu_get(cpu);
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) =
+ cpufreq_cpu_get(cpu);
+
if (!policy) {
ret = -EPROBE_DEFER;
goto err;
}
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 +310,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 +322,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