Skip to content

Commit e520d0b

Browse files
GustavoARSilvavireshk
authored andcommitted
cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug
Allocate extra space for terminating element at: drivers/cpufreq/brcmstb-avs-cpufreq.c: 449 table[i].frequency = CPUFREQ_TABLE_END; and add code comment to make this clear. This fixes the following -Warray-bounds warning seen after building ARM with multi_v7_defconfig (GCC 13): In function 'brcm_avs_get_freq_table', inlined from 'brcm_avs_cpufreq_init' at drivers/cpufreq/brcmstb-avs-cpufreq.c:623:15: drivers/cpufreq/brcmstb-avs-cpufreq.c:449:28: warning: array subscript 5 is outside array bounds of 'void[60]' [-Warray-bounds=] 449 | table[i].frequency = CPUFREQ_TABLE_END; In file included from include/linux/node.h:18, from include/linux/cpu.h:17, from include/linux/cpufreq.h:12, from drivers/cpufreq/brcmstb-avs-cpufreq.c:44: In function 'devm_kmalloc_array', inlined from 'devm_kcalloc' at include/linux/device.h:328:9, inlined from 'brcm_avs_get_freq_table' at drivers/cpufreq/brcmstb-avs-cpufreq.c:437:10, inlined from 'brcm_avs_cpufreq_init' at drivers/cpufreq/brcmstb-avs-cpufreq.c:623:15: include/linux/device.h:323:16: note: at offset 60 into object of size 60 allocated by 'devm_kmalloc' 323 | return devm_kmalloc(dev, bytes, flags); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -Warray-bounds. Link: KSPP#324 Fixes: de322e0 ("cpufreq: brcmstb-avs-cpufreq: AVS CPUfreq driver for Broadcom STB SoCs") Cc: [email protected] Signed-off-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent 6b6349d commit e520d0b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/cpufreq/brcmstb-avs-cpufreq.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,11 @@ brcm_avs_get_freq_table(struct device *dev, struct private_data *priv)
434434
if (ret)
435435
return ERR_PTR(ret);
436436

437-
table = devm_kcalloc(dev, AVS_PSTATE_MAX + 1, sizeof(*table),
437+
/*
438+
* We allocate space for the 5 different P-STATES AVS,
439+
* plus extra space for a terminating element.
440+
*/
441+
table = devm_kcalloc(dev, AVS_PSTATE_MAX + 1 + 1, sizeof(*table),
438442
GFP_KERNEL);
439443
if (!table)
440444
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)