Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754671AbbBBPpF (ORCPT ); Mon, 2 Feb 2015 10:45:05 -0500 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:40618 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753261AbbBBPpB (ORCPT ); Mon, 2 Feb 2015 10:45:01 -0500 Date: Mon, 2 Feb 2015 15:44:50 +0000 From: Javi Merino To: Steven Rostedt Cc: "linux-pm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Punit Agrawal , "broonie@kernel.org" , Zhang Rui , Eduardo Valentin , Frederic Weisbecker , Ingo Molnar Subject: Re: [PATCH v1 5/7] thermal: add trace events to the power allocator governor Message-ID: <20150202154450.GA8092@e104805> References: <1422464438-16761-1-git-send-email-javi.merino@arm.com> <1422464438-16761-6-git-send-email-javi.merino@arm.com> <20150128123106.05e28afc@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150128123106.05e28afc@gandalf.local.home> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1487 Lines: 44 On Wed, Jan 28, 2015 at 05:31:06PM +0000, Steven Rostedt wrote: > On Wed, 28 Jan 2015 17:00:36 +0000 > Javi Merino 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/