[PATCH v1 08/10] cpufreq: Use __free() for policy reference counting cleanup

Rafael J. Wysocki
2025-03-28T20:51:43Z

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Use __free() for policy reference counting cleanup where applicable in
the cpufreq core.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/cpufreq/cpufreq.c | 57 ++++++++++++++++++++--------------------------
1 file changed, 25 insertions(+), 32 deletions(-)

--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1790,27 +1790,26 @@
*/
unsigned int cpufreq_quick_get(unsigned int cpu)
{
- struct cpufreq_policy *policy;
- unsigned int ret_freq = 0;
+ struct cpufreq_policy *policy __free(put_cpufreq_policy) = NULL;
unsigned long flags;

read_lock_irqsave(&cpufreq_driver_lock, flags);

if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) {
- ret_freq = cpufreq_driver->get(cpu);
+ unsigned int ret_freq = cpufreq_driver->get(cpu);
+
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
+
return ret_freq;
}

read_unlock_irqrestore(&cpufreq_driver_lock, flags);

policy = cpufreq_cpu_get(cpu);
- if (policy) {
- ret_freq = policy->cur;
- cpufreq_cpu_put(policy);
- }
+ if (policy)
+ return policy->cur;

- return ret_freq;
+ return 0;
}
EXPORT_SYMBOL(cpufreq_quick_get);

@@ -1822,15 +1821,13 @@
*/
unsigned int cpufreq_quick_get_max(unsigned int cpu)
{
- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
- unsigned int ret_freq = 0;
+ struct cpufreq_policy *policy __free(put_cpufreq_policy);

- if (policy) {
- ret_freq = policy->max;
- cpufreq_cpu_put(policy);
- }
+ policy = cpufreq_cpu_get(cpu);
+ if (policy)
+ return policy->max;

- return ret_freq;
+ return 0;
}
EXPORT_SYMBOL(cpufreq_quick_get_max);

@@ -1842,15 +1839,13 @@
*/
__weak unsigned int cpufreq_get_hw_max_freq(unsigned int cpu)
{
- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
- unsigned int ret_freq = 0;
+ struct cpufreq_policy *policy __free(put_cpufreq_policy);

- if (policy) {
- ret_freq = policy->cpuinfo.max_freq;
- cpufreq_cpu_put(policy);
- }
+ policy = cpufreq_cpu_get(cpu);
+ if (policy)
+ return policy->cpuinfo.max_freq;

- return ret_freq;
+ return 0;
}
EXPORT_SYMBOL(cpufreq_get_hw_max_freq);

@@ -1870,20 +1865,18 @@
*/
unsigned int cpufreq_get(unsigned int cpu)
{
- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
- unsigned int ret_freq = 0;
+ struct cpufreq_policy *policy __free(put_cpufreq_policy);

+ policy = cpufreq_cpu_get(cpu);
if (!policy)
return 0;

- scoped_guard(cpufreq_policy_read, policy) {
- if (cpufreq_driver->get)
- ret_freq = __cpufreq_get(policy);
- }
+ guard(cpufreq_policy_read)(policy);

- cpufreq_cpu_put(policy);
+ if (cpufreq_driver->get)
+ return __cpufreq_get(policy);

- return ret_freq;
+ return 0;
}
EXPORT_SYMBOL(cpufreq_get);

@@ -2538,7 +2531,8 @@
*/
int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
{
- struct cpufreq_policy *cpu_policy;
+ struct cpufreq_policy *cpu_policy __free(put_cpufreq_policy);
+
if (!policy)
return -EINVAL;

@@ -2548,7 +2542,6 @@

memcpy(policy, cpu_policy, sizeof(*policy));

- cpufreq_cpu_put(cpu_policy);
return 0;
}
EXPORT_SYMBOL(cpufreq_get_policy);