Skip to content

Commit 5ec6a40

Browse files
johnhubbardgregkh
authored andcommitted
cpufreq: powernv: fix stack bloat and hard limit on number of CPUs
commit db0d32d upstream. The following build warning occurred on powerpc 64-bit builds: drivers/cpufreq/powernv-cpufreq.c: In function 'init_chip_info': drivers/cpufreq/powernv-cpufreq.c:1070:1: warning: the frame size of 1040 bytes is larger than 1024 bytes [-Wframe-larger-than=] This is with a cross-compiler based on gcc 8.1.0, which I got from: https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.1.0/ The warning is due to putting 1024 bytes on the stack: unsigned int chip[256]; ...and it's also undesirable to have a hard limit on the number of CPUs here. Fix both problems by dynamically allocating based on num_possible_cpus, as recommended by Michael Ellerman. Fixes: 053819e ("cpufreq: powernv: Handle throttling due to Pmax capping at chip level") Signed-off-by: John Hubbard <jhubbard@nvidia.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Cc: 4.10+ <stable@vger.kernel.org> # 4.10+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1b5d4a3 commit 5ec6a40

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

drivers/cpufreq/powernv-cpufreq.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,14 @@ static struct cpufreq_driver powernv_cpufreq_driver = {
10411041

10421042
static int init_chip_info(void)
10431043
{
1044-
unsigned int chip[256];
1044+
unsigned int *chip;
10451045
unsigned int cpu, i;
10461046
unsigned int prev_chip_id = UINT_MAX;
1047+
int ret = 0;
1048+
1049+
chip = kcalloc(num_possible_cpus(), sizeof(*chip), GFP_KERNEL);
1050+
if (!chip)
1051+
return -ENOMEM;
10471052

10481053
for_each_possible_cpu(cpu) {
10491054
unsigned int id = cpu_to_chip_id(cpu);
@@ -1055,8 +1060,10 @@ static int init_chip_info(void)
10551060
}
10561061

10571062
chips = kcalloc(nr_chips, sizeof(struct chip), GFP_KERNEL);
1058-
if (!chips)
1059-
return -ENOMEM;
1063+
if (!chips) {
1064+
ret = -ENOMEM;
1065+
goto free_and_return;
1066+
}
10601067

10611068
for (i = 0; i < nr_chips; i++) {
10621069
chips[i].id = chip[i];
@@ -1066,7 +1073,9 @@ static int init_chip_info(void)
10661073
per_cpu(chip_info, cpu) = &chips[i];
10671074
}
10681075

1069-
return 0;
1076+
free_and_return:
1077+
kfree(chip);
1078+
return ret;
10701079
}
10711080

10721081
static inline void clean_chip_info(void)

0 commit comments

Comments
 (0)