linux_dsm_epyc7002/drivers/input/keyboard
Kees Cook a86854d0c5 treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:

        devm_kzalloc(handle, a * b, gfp)

with:
        devm_kcalloc(handle, a * b, gfp)

as well as handling cases of:

        devm_kzalloc(handle, a * b * c, gfp)

with:

        devm_kzalloc(handle, array3_size(a, b, c), gfp)

as it's slightly less ugly than:

        devm_kcalloc(handle, array_size(a, b), c, gfp)

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

        devm_kzalloc(handle, 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.

Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".

The Coccinelle script used for this was:

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

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

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

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

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

(
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

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

- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	SIZE * COUNT
+	COUNT, SIZE
  , ...)

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

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

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

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

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

(
  devm_kzalloc(HANDLE,
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  devm_kzalloc(HANDLE,
-	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 HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@

(
  devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
  devm_kzalloc(HANDLE,
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  devm_kzalloc(HANDLE,
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  devm_kzalloc(HANDLE,
-	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 HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@

(
  devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
  devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
  devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
  devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * (E2)
+	E2, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(TYPE) * E2
+	E2, sizeof(TYPE)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * (E2)
+	E2, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	sizeof(THING) * E2
+	E2, sizeof(THING)
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	(E1) * E2
+	E1, E2
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	(E1) * (E2)
+	E1, E2
  , ...)
|
- devm_kzalloc
+ devm_kcalloc
  (HANDLE,
-	E1 * E2
+	E1, E2
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
adc-keys.c Input: keyboard - drop calls to platform_set_drvdata and i2c_set_clientdata 2017-01-21 23:51:49 -08:00
adp5520-keys.c Input: keyboard - drop unnecessary calls to input_set_drvdata 2017-01-22 17:22:25 -08:00
adp5588-keys.c gpio: adp5588: move header file out of I2C realm 2017-05-29 13:36:45 +02:00
adp5589-keys.c input: adp5589-keys: use gpiochip data pointer 2016-03-30 10:54:33 +02:00
amikbd.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2014-12-17 10:06:02 -08:00
atakbd.c Input: atari - enable the 102nd key for German keyboards 2015-01-18 00:10:28 -08:00
atkbd.c Input: iatkbd - constify serio_device_id 2017-08-18 17:14:19 -07:00
bcm-keypad.c Input: matrix-keypad - switch to using generic device properties 2017-01-31 11:31:48 -08:00
cap11xx.c treewide: Use struct_size() for devm_kmalloc() and friends 2018-06-06 11:15:43 -07:00
clps711x-keypad.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
cros_ec_keyb.c Input: cros_ec_keyb - mark cros_ec_keyb driver as wake enabled device. 2018-05-30 16:42:12 -07:00
davinci_keyscan.c Input: keyboard - use local variables consistently 2017-01-21 23:51:54 -08:00
dlink-dir685-touchkeys.c Input: add D-Link DIR-685 touchkeys driver 2017-06-05 15:35:32 -07:00
ep93xx_keypad.c input: keyboard: drop owner assignment from platform_drivers 2014-10-20 16:20:39 +02:00
goldfish_events.c Input: goldfish_events - enable ACPI-based enumeration for goldfish events 2016-03-02 09:39:00 -08:00
gpio_keys_polled.c This is the bulk of GPIO changes for the v4.11 cycle 2017-02-23 08:46:04 -08:00
gpio_keys.c Input: gpio-keys - add support for wakeup event action 2018-03-14 10:13:22 -07:00
hil_kbd.c Input: hil_kbd - constify serio_device_id 2017-08-18 17:14:20 -07:00
hilkbd.c parisc/input/hilkbd: Fix section mismatches 2017-08-22 16:34:37 +02:00
hpps2atkbd.h
imx_keypad.c Input: keyboard - convert timers to use timer_setup() 2017-10-24 10:04:44 -07:00
ipaq-micro-keys.c Input: driver for microcontroller keys on the iPaq h3xxx 2015-03-06 11:25:31 -08:00
jornada680_kbd.c Input: keyboard - drop calls to platform_set_drvdata and i2c_set_clientdata 2017-01-21 23:51:49 -08:00
jornada720_kbd.c Input: jornada720_kbd - remove unneeded mach/hardware.h include 2016-09-10 10:47:47 -07:00
Kconfig input: Add MediaTek PMIC keys support 2018-04-16 15:16:11 +01:00
lkkbd.c Input: lkkbd - constify serio_device_id 2017-08-18 17:14:21 -07:00
lm8323.c Input: lm8323 - move header file out of I2C realm 2017-05-22 17:23:46 -07:00
lm8333.c Input: drop owner assignment from i2c_driver 2015-07-17 16:57:00 -07:00
locomokbd.c Input: keyboard - convert timers to use timer_setup() 2017-10-24 10:04:44 -07:00
lpc32xx-keys.c Input: matrix-keypad - switch to using generic device properties 2017-01-31 11:31:48 -08:00
Makefile input: Add MediaTek PMIC keys support 2018-04-16 15:16:11 +01:00
maple_keyb.c Input: keyboard - drop unnecessary calls to input_set_drvdata 2017-01-22 17:22:25 -08:00
matrix_keypad.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
max7359_keypad.c Input: keyboard - drop calls to platform_set_drvdata and i2c_set_clientdata 2017-01-21 23:51:49 -08:00
mcs_touchkey.c Input: mcs - move header file out of I2C realm 2017-05-22 17:26:57 -07:00
mpr121_touchkey.c Input: keyboard - use local variables consistently 2017-01-21 23:51:54 -08:00
mtk-pmic-keys.c input: Add MediaTek PMIC keys support 2018-04-16 15:16:11 +01:00
newtonkbd.c Input: newtonkbd - constify serio_device_id 2017-08-18 17:14:58 -07:00
nomadik-ske-keypad.c Input: nomadik-ske-keypad - fix a trivial typo 2015-10-22 23:31:22 -07:00
nspire-keypad.c Input: keyboard - drop calls to platform_set_drvdata and i2c_set_clientdata 2017-01-21 23:51:49 -08:00
omap4-keypad.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
omap-keypad.c Input: keyboard - convert timers to use timer_setup() 2017-10-24 10:04:44 -07:00
opencores-kbd.c Input: keyboard - drop unnecessary calls to input_set_drvdata 2017-01-22 17:22:25 -08:00
pmic8xxx-keypad.c Input: pmic8xxx-keypad - remove unneeded MODULE_VERSION() usage 2018-01-16 16:48:21 -08:00
pxa27x_keypad.c Input: pxa27x_keypad - handle return value of clk_prepare_enable 2017-08-31 11:57:35 -07:00
pxa930_rotary.c input: keyboard: drop owner assignment from platform_drivers 2014-10-20 16:20:39 +02:00
qt1070.c Input: qt1070 - add OF device ID table 2017-03-23 14:46:33 -07:00
qt2160.c Input: drop owner assignment from i2c_driver 2015-07-17 16:57:00 -07:00
samsung-keypad.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
sh_keysc.c Input: delete non-required instances of include <linux/init.h> 2014-01-06 23:23:57 -08:00
snvs_pwrkey.c Input: keyboard - convert timers to use timer_setup() 2017-10-24 10:04:44 -07:00
spear-keyboard.c Input: keyboard - drop unnecessary calls to device_init_wakeup 2017-01-21 23:53:19 -08:00
st-keyscan.c Input: matrix-keypad - switch to using generic device properties 2017-01-31 11:31:48 -08:00
stmpe-keypad.c Input: stmpe-keypad - remove VLA usage 2018-03-10 10:18:33 -08:00
stowaway.c Input: stowaway - constify serio_device_id 2017-08-18 17:15:00 -07:00
sun4i-lradc-keys.c Input: keyboard - drop calls to platform_set_drvdata and i2c_set_clientdata 2017-01-21 23:51:49 -08:00
sunkbd.c Input: sunkbd - constify serio_device_id 2017-08-18 17:15:04 -07:00
tc3589x-keypad.c Input: tc3589x-keypad - remove stray ')' 2016-05-25 17:37:15 -07:00
tca6416-keypad.c Input: use dev_get_platdata() 2013-12-06 02:06:29 -08:00
tca8418_keypad.c Input: tca8418 - enable interrupt after it has been requested 2017-10-19 16:50:20 -07:00
tegra-kbc.c Input: keyboard - convert timers to use timer_setup() 2017-10-24 10:04:44 -07:00
tm2-touchkey.c Input: tm2-touchkey - use LEN_ON as boolean value instead of LED_FULL 2017-06-01 22:08:05 -07:00
twl4030_keypad.c mfd: twl: Move header file out of I2C realm 2017-09-04 14:41:02 +01:00
w90p910_keypad.c input: keyboard: drop owner assignment from platform_drivers 2014-10-20 16:20:39 +02:00
xtkbd.c Input: xtkbd - constify serio_device_id 2017-08-18 17:15:07 -07:00