From patchwork Thu Feb 2 14:46:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9552055 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2BF08602F0 for ; Thu, 2 Feb 2017 14:49:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CF0D26E77 for ; Thu, 2 Feb 2017 14:49:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1144628456; Thu, 2 Feb 2017 14:49:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A9CC26E77 for ; Thu, 2 Feb 2017 14:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751484AbdBBOtA (ORCPT ); Thu, 2 Feb 2017 09:49:00 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:54098 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751045AbdBBOs5 (ORCPT ); Thu, 2 Feb 2017 09:48:57 -0500 Received: from wuerfel.lan ([78.42.17.5]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.129]) with ESMTPA (Nemesis) id 0MFDJ5-1cf8MM28fz-00GJuR; Thu, 02 Feb 2017 15:48:25 +0100 From: Arnd Bergmann To: Amit Daniel Kachhap , Viresh Kumar , Javi Merino , Zhang Rui , Eduardo Valentin Cc: Arnd Bergmann , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] thermal: use cpumask_var_t for on-stack cpu masks Date: Thu, 2 Feb 2017 15:46:26 +0100 Message-Id: <20170202144821.3721926-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:lGHR0/q7VVYVnbeoXsrJdof7eBZzZ5ibS2k5ReAGQjRLcqiP4t3 LJlfQqkUw3sI0WeuNUT0csGkpZpxZmxUEGNEZVPneZGsxn6u/hum3683D1xcVgig9u/hJLG zSHC7ERuvxyRQ7pGFwf1Iv/aPXlgdRdoFKQuNJ3yZil8XFz+/nVoB3+2ZFaKiVL9PSXgWpx N/w8wn3v4melwUdefDpMw== X-UI-Out-Filterresults: notjunk:1; V01:K0:4ibU7HPPMjs=:WfwipmtSrnTDU+FfvRI6RR RcDJ3Un+bDzZplcLmGYePt7LbCGdLIcaTvr8xaeqTz2R1Mk3EarCvw5kFau2haO2AJzQdAeLK TT/2YytzNlVNi3J/nMB+Tr06MrQIuEGJiYc0h17c77G2QWGPAxjqxaeQaxuBkLZOvxvOPcnJV 37NYXaw1c75nYrepAbs15qjMwU7LUMUxHwX+neckS/qr/b0ur7HOo9lCjv2MVk0KsIiET/KMj KEZQg9WC9dHlCqYlqnq7zwrskFOm2v0KZwLeq9pklqXtmCJo53SbGWMtZWImoifUZ/VhpPXig mARZ28wObE5n/zMHvZQyuZ6VgcgUguLsXp5p9SuFGGosBs733sPQlg7WdqIs61wTD2f3Slc6u UyRI0I0kClJeJliIN2x0uXz+SsWg0HdpM2Nd5ZUJCRn+A4SKjPbShUIgXoqwYHKiAjqBMa1BP Aqb6gQVhHBdprZo5hCJE64ujEMde43ZuXz4ZlM65msGYgIBEynQuYXEiri5kFIptwTWXGzJi4 /2m5c1hx8lJ6aqmE8ImIFAlR1Db4W0d3Et5ATGjyYh1eCwdr5wYE8pOU57usPDMyGFCOjU/Gt saNpVkz6OM66Vmzp8u0Rj3wPyVKP38D1Au0HFKVBTuZvbmdpr9PbeBEjk043G8w+TG1cbJ4eQ bwn0G9MBiYuw4KuvC+gJBm6j5pH8EykeKEjQq7ibLNsHb1qRmKNCFR4T+3kgBilK6Ju4= Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Putting a bare cpumask structure on the stack produces a warning on large SMP configurations: drivers/thermal/cpu_cooling.c: In function 'cpufreq_state2power': drivers/thermal/cpu_cooling.c:644:1: warning: the frame size of 1056 bytes is larger than 1024 bytes [-Wframe-larger-than=] drivers/thermal/cpu_cooling.c: In function '__cpufreq_cooling_register': drivers/thermal/cpu_cooling.c:898:1: warning: the frame size of 1104 bytes is larger than 1024 bytes [-Wframe-larger-than=] The recommended workaround is to use cpumask_var_t, which behaves just like a normal cpu mask in most cases, but turns into a dynamic allocation when CONFIG_CPUMASK_OFFSTACK is set. Signed-off-by: Arnd Bergmann Acked-by: Viresh Kumar --- drivers/thermal/cpu_cooling.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index ca7ddaea450c..1d7f7e85f669 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -609,31 +609,39 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, unsigned long state, u32 *power) { unsigned int freq, num_cpus; - cpumask_t cpumask; + cpumask_var_t cpumask; u32 static_power, dynamic_power; int ret; struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; - cpumask_and(&cpumask, &cpufreq_device->allowed_cpus, cpu_online_mask); - num_cpus = cpumask_weight(&cpumask); + if (!alloc_cpumask_var(&cpumask, GFP_KERNEL)) + return -ENOMEM; + + cpumask_and(cpumask, &cpufreq_device->allowed_cpus, cpu_online_mask); + num_cpus = cpumask_weight(cpumask); /* None of our cpus are online, so no power */ if (num_cpus == 0) { *power = 0; - return 0; + ret = 0; + goto out; } freq = cpufreq_device->freq_table[state]; - if (!freq) - return -EINVAL; + if (!freq) { + ret = -EINVAL; + goto out; + } dynamic_power = cpu_freq_to_power(cpufreq_device, freq) * num_cpus; ret = get_static_power(cpufreq_device, tz, freq, &static_power); if (ret) - return ret; + goto out; *power = static_power + dynamic_power; - return 0; +out: + free_cpumask_var(cpumask); + return ret;; } /** @@ -759,16 +767,20 @@ __cpufreq_cooling_register(struct device_node *np, struct cpufreq_cooling_device *cpufreq_dev; char dev_name[THERMAL_NAME_LENGTH]; struct cpufreq_frequency_table *pos, *table; - struct cpumask temp_mask; + cpumask_var_t temp_mask; unsigned int freq, i, num_cpus; int ret; struct thermal_cooling_device_ops *cooling_ops; - cpumask_and(&temp_mask, clip_cpus, cpu_online_mask); - policy = cpufreq_cpu_get(cpumask_first(&temp_mask)); + if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL)) + return ERR_PTR(-ENOMEM); + + cpumask_and(temp_mask, clip_cpus, cpu_online_mask); + policy = cpufreq_cpu_get(cpumask_first(temp_mask)); if (!policy) { pr_debug("%s: CPUFreq policy not found\n", __func__); - return ERR_PTR(-EPROBE_DEFER); + cool_dev = ERR_PTR(-EPROBE_DEFER); + goto free_cpumask; } table = policy->freq_table; @@ -886,7 +898,8 @@ __cpufreq_cooling_register(struct device_node *np, kfree(cpufreq_dev); put_policy: cpufreq_cpu_put(policy); - +free_cpumask: + free_cpumask_var(temp_mask); return cool_dev; }