Skip to content

Commit bdefd99

Browse files
lukaszluba-armrafaeljw
authored andcommitted
powercap: DTPM: Fix missing cpufreq_cpu_put() calls
The policy returned by cpufreq_cpu_get() has to be released with the help of cpufreq_cpu_put() to balance its kobject reference counter properly. Add the missing calls to cpufreq_cpu_put() in the code. Fixes: 0aea2e4 ("powercap/dtpm_cpu: Reset per_cpu variable in the release function") Fixes: 0e8f68d ("powercap/drivers/dtpm: Add CPU energy model based support") Cc: v5.16+ <[email protected]> # v5.16+ Signed-off-by: Lukasz Luba <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 33cc938 commit bdefd99

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

drivers/powercap/dtpm_cpu.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ static void pd_release(struct dtpm *dtpm)
140140
if (policy) {
141141
for_each_cpu(dtpm_cpu->cpu, policy->related_cpus)
142142
per_cpu(dtpm_per_cpu, dtpm_cpu->cpu) = NULL;
143+
144+
cpufreq_cpu_put(policy);
143145
}
144146

145147
kfree(dtpm_cpu);
@@ -191,12 +193,16 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
191193
return 0;
192194

193195
pd = em_cpu_get(cpu);
194-
if (!pd || em_is_artificial(pd))
195-
return -EINVAL;
196+
if (!pd || em_is_artificial(pd)) {
197+
ret = -EINVAL;
198+
goto release_policy;
199+
}
196200

197201
dtpm_cpu = kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL);
198-
if (!dtpm_cpu)
199-
return -ENOMEM;
202+
if (!dtpm_cpu) {
203+
ret = -ENOMEM;
204+
goto release_policy;
205+
}
200206

201207
dtpm_init(&dtpm_cpu->dtpm, &dtpm_ops);
202208
dtpm_cpu->cpu = cpu;
@@ -216,6 +222,7 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
216222
if (ret)
217223
goto out_dtpm_unregister;
218224

225+
cpufreq_cpu_put(policy);
219226
return 0;
220227

221228
out_dtpm_unregister:
@@ -227,6 +234,8 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
227234
per_cpu(dtpm_per_cpu, cpu) = NULL;
228235
kfree(dtpm_cpu);
229236

237+
release_policy:
238+
cpufreq_cpu_put(policy);
230239
return ret;
231240
}
232241

0 commit comments

Comments
 (0)