1
0
Fork 0
alistair23-linux/drivers/cpufreq
Kees Cook 6da2ec5605 treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:

        kmalloc(a * b, gfp)

with:
        kmalloc_array(a * b, gfp)

as well as handling cases of:

        kmalloc(a * b * c, gfp)

with:

        kmalloc(array3_size(a, b, c), gfp)

as it's slightly less ugly than:

        kmalloc_array(array_size(a, b), c, gfp)

This does, however, attempt to ignore constant size factors like:

        kmalloc(4 * 1024, gfp)

though any constants defined via macros get caught up in the conversion.

Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.

The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().

The Coccinelle script used for this was:

// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@

(
  kmalloc(
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  kmalloc(
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@

(
  kmalloc(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(unsigned char) * COUNT
+	COUNT
  , ...)
)

// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@

(
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@

- kmalloc
+ kmalloc_array
  (
-	SIZE * COUNT
+	COUNT, SIZE
  , ...)

// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@

(
  kmalloc(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
)

// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@

(
  kmalloc(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
)

// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@

(
  kmalloc(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
)

// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  kmalloc(C1 * C2 * C3, ...)
|
  kmalloc(
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
  kmalloc(sizeof(THING) * C2, ...)
|
  kmalloc(sizeof(TYPE) * C2, ...)
|
  kmalloc(C1 * C2 * C3, ...)
|
  kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (E2)
+	E2, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * E2
+	E2, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (E2)
+	E2, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * E2
+	E2, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	(E1) * E2
+	E1, E2
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	(E1) * (E2)
+	E1, E2
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	E1 * E2
+	E1, E2
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
Kconfig cpufreq: remove at32ap-cpufreq 2018-02-07 11:44:23 +01:00
Kconfig.arm cpufreq: Add Kryo CPU scaling driver 2018-05-30 12:53:11 +02:00
Kconfig.powerpc cpufreq: qoriq: rename the driver 2015-03-18 22:35:16 +01:00
Kconfig.x86 sched/x86: Change CONFIG_SCHED_ITMT to CONFIG_SCHED_MC_PRIO 2016-11-30 08:27:08 +01:00
Makefile cpufreq: Add Kryo CPU scaling driver 2018-05-30 12:53:11 +02:00
acpi-cpufreq.c cpufreq: ACPI: Don't validate the frequency table twice 2018-03-20 12:07:51 +01:00
amd_freq_sensitivity.c cpufreq: AMD: Ignore the check for ProcFeedback in ST/CZ 2018-02-07 11:26:37 +01:00
arm_big_little.c cpufreq: arm_big_little: Don't validate the frequency table twice 2018-03-20 12:07:51 +01:00
arm_big_little.h cpufreq: arm_big_little: make function arguments and structure pointer const 2017-11-08 23:22:19 +01:00
arm_big_little_dt.c cpufreq: arm_big_little: make cpufreq_arm_bL_ops structures const 2017-11-08 23:22:20 +01:00
armada-37xx-cpufreq.c cpufreq: add suspend/resume support in Armada 37xx DVFS driver 2018-05-10 11:43:59 +02:00
bmips-cpufreq.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
brcmstb-avs-cpufreq.c cpufreq: brcmstb-avs-cpufreq: remove development debug support 2018-04-24 11:34:57 +02:00
cppc_cpufreq.c Merge branches 'acpi-cppc', 'acpi-misc', 'acpi-battery' and 'acpi-ac' 2018-06-04 10:43:34 +02:00
cpufreq-dt-platdev.c cpufreq: Add Kryo CPU scaling driver 2018-05-30 12:53:11 +02:00
cpufreq-dt.c cpufreq: dt: Allow platform specific suspend/resume callbacks 2018-05-10 11:43:59 +02:00
cpufreq-dt.h cpufreq: dt: Allow platform specific suspend/resume callbacks 2018-05-10 11:43:59 +02:00
cpufreq-nforce2.c cpufreq: Add CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING cpufreq driver flag 2017-07-26 00:15:46 +02:00
cpufreq.c cpufreq: Use static SRCU initializer 2018-05-30 11:16:59 +02:00
cpufreq_conservative.c cpufreq: governor: Drop min_sampling_rate 2017-07-22 02:25:20 +02:00
cpufreq_governor.c cpufreq: Rename cpufreq_can_do_remote_dvfs() 2018-05-23 10:37:08 +02:00
cpufreq_governor.h cpufreq: Replace "max_transition_latency" with "dynamic_switching" 2017-07-26 00:15:45 +02:00
cpufreq_governor_attr_set.c cpufreq: governor: Move abstract gov_attr_set code to seperate file 2016-04-02 01:09:01 +02:00
cpufreq_ondemand.c cpufreq: governor: Drop min_sampling_rate 2017-07-22 02:25:20 +02:00
cpufreq_ondemand.h cpufreq: ondemand: Don't keep a copy of freq_table pointer 2016-06-09 00:58:06 +02:00
cpufreq_performance.c cpufreq: governor: Get rid of governor events 2016-06-02 23:24:15 +02:00
cpufreq_powersave.c cpufreq: governor: Get rid of governor events 2016-06-02 23:24:15 +02:00
cpufreq_stats.c cpufreq: stats: Change return type of cpufreq_stats_update() as void 2018-01-05 13:22:46 +01:00
cpufreq_userspace.c cpufreq: governor: Get rid of governor events 2016-06-02 23:24:15 +02:00
davinci-cpufreq.c ARM: davinci: da850: fix da850_set_pll0rate() 2017-01-02 15:02:51 +05:30
e_powersaver.c cpufreq: e_powersaver: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
elanfreq.c cpufreq: elanfreq: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
exynos5440-cpufreq.c cpufreq: Add and use cpufreq_for_each_{valid_,}entry_idx() 2018-02-08 10:21:39 +01:00
freq_table.c cpufreq: Drop cpufreq_table_validate_and_show() 2018-04-10 08:40:45 +02:00
gx-suspmod.c cpufreq: Add CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING cpufreq driver flag 2017-07-26 00:15:46 +02:00
highbank-cpufreq.c Merge branch 'mailbox-for-linus' of git://git.linaro.org/landing-teams/working/fujitsu/integration 2014-10-21 11:21:19 -07:00
ia64-acpi-cpufreq.c cpufreq: ia64-acpi: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
imx6q-cpufreq.c cpufreq: imx6q: Find max freq from frequency table itself 2018-03-20 12:07:51 +01:00
intel_pstate.c cpufreq: intel_pstate: allow trace in passive mode 2018-05-14 23:34:25 +02:00
kirkwood-cpufreq.c cpufreq: kirkwood-cpufreq:- Handle return value of clk_prepare_enable() 2017-05-30 00:09:41 +02:00
longhaul.c cpufreq: longhaul: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
longhaul.h cpufreq: delete __cpuinit usage from all cpufreq files 2013-07-14 19:36:57 -04:00
longrun.c cpufreq: Don't set transition_latency for setpolicy drivers 2017-07-26 00:15:43 +02:00
loongson1-cpufreq.c CPUFREQ: Loongson1: Replace goto out with return in ls1x_cpufreq_probe() 2016-05-13 14:02:08 +02:00
loongson2_cpufreq.c cpufreq: Loongson2: constify platform_device_id 2017-08-18 01:44:21 +02:00
maple-cpufreq.c cpufreq: Use consistent prefixing via pr_fmt 2016-04-09 01:35:18 +02:00
mediatek-cpufreq.c cpufreq: mediatek: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
mvebu-cpufreq.c cpufreq: mvebu: Free opp if registering failed 2017-12-16 02:29:43 +01:00
omap-cpufreq.c PM / OPP: Update OPP users to put reference 2017-01-30 09:22:21 +01:00
p4-clockmod.c cpufreq: p4-clockmod: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
pasemi-cpufreq.c cpufreq: Add and use cpufreq_for_each_{valid_,}entry_idx() 2018-02-08 10:21:39 +01:00
pcc-cpufreq.c Revert "cpufreq: pcc-cpufreq: update default value of cpuinfo_transition_latency" 2016-07-22 23:51:06 +02:00
pmac32-cpufreq.c cpufreq: Add CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING cpufreq driver flag 2017-07-26 00:15:46 +02:00
pmac64-cpufreq.c cpufreq: Convert to using %pOF instead of full_name 2017-08-25 01:20:46 +02:00
powernow-k6.c cpufreq: powernow: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
powernow-k7.c cpufreq: powernow: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
powernow-k7.h [CPUFREQ] Move x86 drivers to drivers/cpufreq/ 2011-05-19 18:51:07 -04:00
powernow-k8.c cpufreq: powernow: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
powernow-k8.h cpufreq: powernow-k8: Suppress checkpatch warnings 2014-05-17 01:27:01 +02:00
powernv-cpufreq.c cpufreq: powernv: Fix hardlockup due to synchronous smp_call in timer interrupt 2018-04-27 16:16:10 +10:00
ppc_cbe_cpufreq.c cpufreq: ppc_cbe: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
ppc_cbe_cpufreq.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ppc_cbe_cpufreq_pervasive.c cpufreq: powerpc/platforms/cell: move cpufreq driver to drivers/cpufreq 2013-04-10 13:19:26 +02:00
ppc_cbe_cpufreq_pmi.c cpufreq: Remove CPUFREQ_START notifier event 2017-02-04 00:05:30 +01:00
pxa2xx-cpufreq.c cpufreq: pxa: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
pxa3xx-cpufreq.c cpufreq: pxa: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
qcom-cpufreq-kryo.c cpufreq: Add Kryo CPU scaling driver 2018-05-30 12:53:11 +02:00
qoriq-cpufreq.c cpufreq: qoirq: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
s3c24xx-cpufreq-debugfs.c cpufreq: Use consistent prefixing via pr_fmt 2016-04-09 01:35:18 +02:00
s3c24xx-cpufreq.c cpufreq: s3c24xx: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
s3c64xx-cpufreq.c cpufreq: s3c64xx: remove incorrect __init annotation 2016-12-21 02:54:18 +01:00
s3c2410-cpufreq.c cpufreq: s3c24xx: Remove some dead code 2014-07-19 04:24:59 +09:00
s3c2412-cpufreq.c cpufreq: Use consistent prefixing via pr_fmt 2016-04-09 01:35:18 +02:00
s3c2416-cpufreq.c cpufreq: s3c2416: double free on driver init error path 2017-02-09 01:22:45 +01:00
s3c2440-cpufreq.c cpufreq: s3c2440: fix spelling mistake: "divsiors" -> "divisors" 2018-05-10 11:50:42 +02:00
s5pv210-cpufreq.c cpufreq: s5pv210: add missing of_node_put() 2017-07-26 22:54:01 +02:00
sa1100-cpufreq.c cpufreq: Add CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING cpufreq driver flag 2017-07-26 00:15:46 +02:00
sa1110-cpufreq.c cpufreq: Add CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING cpufreq driver flag 2017-07-26 00:15:46 +02:00
sc520_freq.c cpufreq: sc520: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
scmi-cpufreq.c cpufreq: SCMI: Don't validate the frequency table twice 2018-04-10 08:39:55 +02:00
scpi-cpufreq.c cpufreq: scpi: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
sfi-cpufreq.c cpufreq: sfi: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
sh-cpufreq.c cpufreq: sh: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
sparc-us2e-cpufreq.c cpufreq: sparc: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
sparc-us3-cpufreq.c cpufreq: sparc: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
spear-cpufreq.c cpufreq: SPEAr: pr_err() strings should end with newlines 2017-10-03 02:52:17 +02:00
speedstep-centrino.c cpufreq: speedstep: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
speedstep-ich.c cpufreq: speedstep: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
speedstep-lib.c cpufreq: speedstep: fix speedstep_detect_processor()'s return type 2018-05-10 11:46:00 +02:00
speedstep-lib.h [CPUFREQ] Move x86 drivers to drivers/cpufreq/ 2011-05-19 18:51:07 -04:00
speedstep-smi.c cpufreq: speedstep: Don't validate the frequency table twice 2018-03-20 12:07:52 +01:00
sti-cpufreq.c cpufreq: Convert to using %pOF instead of full_name 2017-08-25 01:20:46 +02:00
tango-cpufreq.c cpufreq: dt: Don't use generic platdev driver for tango 2017-07-22 02:20:59 +02:00
tegra20-cpufreq.c cpufreq: tegra20: Wrap cpufreq into platform driver 2018-05-21 13:44:24 +02:00
tegra124-cpufreq.c cpufreq: tegra124: No need of setting platform-data 2016-04-09 01:12:09 +02:00
tegra186-cpufreq.c cpufreq: tegra186: Don't validate the frequency table twice 2018-03-20 12:07:53 +01:00
ti-cpufreq.c cpufreq: ti-cpufreq: Use builtin_platform_driver() 2018-04-10 08:38:02 +02:00
unicore2-cpufreq.c cpufreq: Add CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING cpufreq driver flag 2017-07-26 00:15:46 +02:00
vexpress-spc-cpufreq.c cpufreq: arm_big_little: make cpufreq_arm_bL_ops structures const 2017-11-08 23:22:20 +01:00