Re: [PATCH] thermal: use cpumask_var_t for on-stack cpu masks
From: Zhang Rui
Date: Fri Feb 10 2017 - 03:43:06 EST
On Thu, 2017-02-02 at 15:46 +0100, Arnd Bergmann wrote:
> 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 <arnd@xxxxxxxx>
> ---
> Â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;;
The patch looks good to me except that there is on redundantÂsemicolon
here.
Patch applied with the typo fixed.
thanks,
rui
> Â}
> Â
> Â/**
> @@ -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;
> Â}
> Â