lkml.org 
[lkml]   [2015]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v1 5/7] thermal: add trace events to the power allocator governor
On Wed, Jan 28, 2015 at 05:31:06PM +0000, Steven Rostedt wrote:
> On Wed, 28 Jan 2015 17:00:36 +0000
> Javi Merino <javi.merino@arm.com> wrote:
>
> > + if (trace_thermal_power_cpu_limit_enabled() && load_cpu) {
> > + trace_thermal_power_cpu_get_power(
> > + &cpufreq_device->allowed_cpus,
> > + freq, load_cpu, i, dynamic_power, static_power);
> > +
> > + devm_kfree(&cdev->device, load_cpu);
>
> You may want to move the devm_kfree() out of the
> trace_thermal_power_cpu_limit_enabled() check. There could be a race
> where that gets disabled while this function is running and you just
> leaked memory.
>
> if (load_cpu)
> devm_kfree(&cdev->device, load_cpu);
>
> should be done by itself.

Good catch! I've changed it to

if (load_cpu) {
trace_thermal_power_cpu_get_power(
&cpufreq_device->allowed_cpus,
freq, load_cpu, i, dynamic_power, static_power);

devm_kfree(&cdev->device, load_cpu);
}

This way, if the trace is disabled while in the function,
trace_thermal_power_cpu_get_power() doesn't get executed but you free
load_cpu. If the opposite happens (the trace gets enabled while in
the function), load_cpu is NULL and you don't pass the NULL pointer to
trace_thermal_power_cpu_get_power().

Cheers,
Javi


\
 
 \ /
  Last update: 2015-02-02 17:01    [W:1.878 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site