From patchwork Wed Aug 19 08:24:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 52521 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id CDFDC218CB for ; Wed, 19 Aug 2015 08:24:25 +0000 (UTC) Received: by lbcli1 with SMTP id li1sf62676631lbc.2 for ; Wed, 19 Aug 2015 01:24:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:in-reply-to:references :date:message-id:subject:from:to:cc:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=iwrJHpNDhX1hAK3d6/yU9el5z2HPc3qoRsvZbHUMTRg=; b=QBmc4R9tUTM5aFZnEMox0gewEJpY/yGGzBvIfAxD8ScNAtKq9frLLOP/jOB5SjXLeZ mih5Ev3F6k/ymkqW6CWUEZokYW+RRTJODhRgzXh2PPxfITjxMMrGDMuN7dqEwmOhklhZ kVXlkRoAUj0JoyAfaC01aTbu9QLh+S8FEYuW8fxf5esT5rOFpTmMupmGo8MgM47++A9d BaNja7sAFDXxnSXszKCugL7mY/yPNGpwRSf9sgib9Kvb3pGvejJizjxN9O4rIkPf8WzE Da58XA/2hMjtOU+tyW9oZDjmeLf+zCFkruTw2vRMjf0Db8tH46BJ6R70ArG0EEh6Ilhf xY1A== X-Gm-Message-State: ALoCoQm5ZbLOxgmLyGTnaxDIKFn2LlzNarKr0H/PTFwHeMwNavNi4mWOGRZDeG5GqXVaUamk07sW X-Received: by 10.112.17.106 with SMTP id n10mr1666532lbd.18.1439972664471; Wed, 19 Aug 2015 01:24:24 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.25.134 with SMTP id c6ls886590lag.54.gmail; Wed, 19 Aug 2015 01:24:24 -0700 (PDT) X-Received: by 10.112.73.33 with SMTP id i1mr10321560lbv.31.1439972664324; Wed, 19 Aug 2015 01:24:24 -0700 (PDT) Received: from mail-lb0-x233.google.com (mail-lb0-x233.google.com. [2a00:1450:4010:c04::233]) by mx.google.com with ESMTPS id o1si16098031lbc.8.2015.08.19.01.24.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Aug 2015 01:24:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::233 as permitted sender) client-ip=2a00:1450:4010:c04::233; Received: by lbcbn3 with SMTP id bn3so118397681lbc.2 for ; Wed, 19 Aug 2015 01:24:23 -0700 (PDT) X-Received: by 10.112.209.106 with SMTP id ml10mr10100310lbc.112.1439972663780; Wed, 19 Aug 2015 01:24:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.162.200 with SMTP id yc8csp203482lbb; Wed, 19 Aug 2015 01:24:22 -0700 (PDT) X-Received: by 10.68.250.5 with SMTP id yy5mr22353348pbc.34.1439972661614; Wed, 19 Aug 2015 01:24:21 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ln7si35057598pbc.164.2015.08.19.01.24.20; Wed, 19 Aug 2015 01:24:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752730AbbHSIYT (ORCPT + 13 others); Wed, 19 Aug 2015 04:24:19 -0400 Received: from mail-ig0-f179.google.com ([209.85.213.179]:33914 "EHLO mail-ig0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752764AbbHSIYS (ORCPT ); Wed, 19 Aug 2015 04:24:18 -0400 Received: by igui7 with SMTP id i7so102418618igu.1; Wed, 19 Aug 2015 01:24:17 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.50.30.36 with SMTP id p4mr337763igh.87.1439972657117; Wed, 19 Aug 2015 01:24:17 -0700 (PDT) Received: by 10.64.176.133 with HTTP; Wed, 19 Aug 2015 01:24:17 -0700 (PDT) In-Reply-To: <20150819062219.GA10032@localhost> References: <20150819062219.GA10032@localhost> Date: Wed, 19 Aug 2015 13:54:17 +0530 Message-ID: Subject: Re: [PATCH] thermal: cpu_cooling: Remove usage of devm functions From: Viresh Kumar To: Vaishali Thakkar Cc: Zhang Rui , Eduardo Valentin , Linux PM list , "linux-kernel@vger.kernel.org" Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::233 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@gmail.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On Wed, Aug 19, 2015 at 11:52 AM, Vaishali Thakkar wrote: > In the function cpufreq_get_requested_power, the memory allocated > for load_cpu is live within the function only. And after the > allocation it is immediately freed with devm_kfree. There is no > need to allocate memory for load_cpu with devm function so replace > devm_kcalloc with kcalloc and devm_kfree with kfree. > > Signed-off-by: Vaishali Thakkar > --- > This patch is having one checkpatch.pl warning which suggests that > kfree(NULL) is safe. But I think leaving code with if is nice > because it reflects the fact that kcalloc was under an if. So, I > have ignored checkpatch. If maintainer wants me to go for changing > things, I am fine with it too. I will rather ask you to do this: for_each_cpu(cpu, &cpufreq_device->allowed_cpus) { @@ -607,22 +607,20 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, dynamic_power = get_dynamic_power(cpufreq_device, freq); ret = get_static_power(cpufreq_device, tz, freq, &static_power); - if (ret) { - if (load_cpu) - devm_kfree(&cdev->device, load_cpu); - return ret; - } + if (ret) + goto free; - if (load_cpu) { + 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); - } - *power = static_power + dynamic_power; - return 0; + +free: + kfree(&cdev->device, load_cpu); + + return ret; } --- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 620dcd405ff6..a04055ea5d94 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -584,8 +584,8 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, if (trace_thermal_power_cpu_get_power_enabled()) { u32 ncpus = cpumask_weight(&cpufreq_device->allowed_cpus); - load_cpu = devm_kcalloc(&cdev->device, ncpus, sizeof(*load_cpu), - GFP_KERNEL); + load_cpu = kcalloc(&cdev->device, ncpus, sizeof(*load_cpu), + GFP_KERNEL); }