1
0
Fork 0
alistair23-linux/drivers/input/misc
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
..
88pm80x_onkey.c Input: misc - drop unnecessary calls to device_init_wakeup 2017-01-21 23:53:21 -08:00
88pm860x_onkey.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
Kconfig Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2018-04-05 13:21:57 -07:00
Makefile Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2018-04-05 13:21:57 -07:00
ab8500-ponkey.c Input: ab8500-ponkey - drop unnecessary call to platform_set_drvdata 2017-01-18 11:49:19 -08:00
ad714x-i2c.c Input: ad714x - convert to using managed resources 2015-09-19 11:42:39 -07:00
ad714x-spi.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2015-11-06 11:57:41 -08:00
ad714x.c Input: ad714x - convert to using managed resources 2015-09-19 11:42:39 -07:00
ad714x.h Input: ad714x - convert to using managed resources 2015-09-19 11:42:39 -07:00
adxl34x-i2c.c Input: adxl34x - make it enumerable in ACPI environment 2017-01-03 12:33:12 -08:00
adxl34x-spi.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
adxl34x.c Input: adxl34x - do not treat FIFO_MODE() as boolean 2017-09-20 12:15:58 -07:00
adxl34x.h
apanel.c Input: remove unneeded MODULE_VERSION() usage in misc input drivers 2018-01-16 16:48:24 -08:00
arizona-haptics.c Linux 4.10-rc5 2017-01-24 12:37:43 -08:00
ati_remote2.c Input: ati_remote2 - fix typo 'can by' to 'can be' 2018-05-15 12:01:09 -07:00
atlas_btns.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
atmel_captouch.c Input: misc - drop calls to platform_set_drvdata and i2c_set_clientdata 2017-01-21 23:51:51 -08:00
axp20x-pek.c Input: axp20x-pek - fix module not auto-loading for axp221 pek 2017-10-19 16:50:28 -07:00
bma150.c Input: bma150 - remove support for bma150 2017-04-01 11:44:53 -07:00
cm109.c Input: cm109 - validate number of endpoints before using them 2017-03-16 13:56:50 -07:00
cma3000_d0x.c Input: use dev_get_platdata() 2013-12-06 02:06:29 -08:00
cma3000_d0x.h
cma3000_d0x_i2c.c Input: drop owner assignment from i2c_driver 2015-07-17 16:57:00 -07:00
cobalt_btns.c input: misc: drop owner assignment from platform_drivers 2014-10-20 16:20:40 +02:00
cpcap-pwrbutton.c input: cpcap-pwrbutton: New driver 2017-04-11 15:18:09 +01:00
da9052_onkey.c input: misc: drop owner assignment from platform_drivers 2014-10-20 16:20:40 +02:00
da9055_onkey.c input: misc: drop owner assignment from platform_drivers 2014-10-20 16:20:40 +02:00
da9063_onkey.c Input: misc - drop calls to platform_set_drvdata and i2c_set_clientdata 2017-01-21 23:51:51 -08:00
dm355evm_keys.c mfd: dm355evm_msp: Move header file out of I2C realm 2017-08-15 08:06:14 +01:00
drv260x.c Input: drv260x - remove OF dependency 2017-03-09 10:00:14 -08:00
drv2665.c Input: drv2665 - fix misuse of regmap_update_bits 2016-11-30 09:03:44 -08:00
drv2667.c Input: drv2667 - fix misuse of regmap_update_bits 2016-11-30 09:03:45 -08:00
e3x0-button.c Input: misc - drop empty remove functions 2017-01-21 23:53:34 -08:00
gp2ap002a00f.c Input: misc - drop unnecessary calls to device_init_wakeup 2017-01-21 23:53:21 -08:00
gpio-beeper.c Input: improve usage of gpiod API 2015-06-16 17:09:14 -07:00
gpio_decoder.c Input: gpio_decoder - drop unnecessary call to platform_set_drvdata 2017-01-18 11:49:13 -08:00
hisi_powerkey.c Input: misc - drop empty remove functions 2017-01-21 23:53:34 -08:00
hp_sdc_rtc.c proc: introduce proc_create_single{,_data} 2018-05-16 07:23:35 +02:00
ideapad_slidebar.c input: misc: drop owner assignment from platform_drivers 2014-10-20 16:20:40 +02:00
ims-pcu.c Input: ims-pcu - fix typo in the error message 2017-11-26 16:16:31 -08:00
ixp4xx-beeper.c input: misc: drop owner assignment from platform_drivers 2014-10-20 16:20:40 +02:00
keyspan_remote.c Input: inline macros for MODULE_LICENSE, etc 2018-01-17 09:52:22 -08:00
kxtj9.c Input: kxtj9 - remove unneeded retval variable 2015-10-02 11:44:17 -07:00
m68kspkr.c input: misc: drop owner assignment from platform_drivers 2014-10-20 16:20:40 +02:00
max8925_onkey.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
max8997_haptic.c pwm: Changes for v4.7-rc1 2016-05-25 10:40:15 -07:00
max77693-haptic.c Linux 4.8 2016-10-13 17:25:40 -07:00
mc13783-pwrbutton.c input: misc: drop owner assignment from platform_drivers 2014-10-20 16:20:40 +02:00
mma8450.c Input: mma8450 - drop unnecessary call to i2c_set_clientdata 2017-01-18 11:49:14 -08:00
palmas-pwrbutton.c Input: constify of_device_id arrays 2015-03-19 12:16:18 -07:00
pcap_keys.c input: misc: drop owner assignment from platform_drivers 2014-10-20 16:20:40 +02:00
pcf8574_keypad.c Input: drop owner assignment from i2c_driver 2015-07-17 16:57:00 -07:00
pcf50633-input.c Input: delete non-required instances of include <linux/init.h> 2014-01-06 23:23:57 -08:00
pcspkr.c Input: pcspkr - fix code style and error value in pcspkr_event 2017-08-14 22:12:05 -07:00
pm8xxx-vibrator.c Input: pm8xxx-vib - add support for pm8916's vibrator 2017-04-05 08:52:39 -07:00
pm8941-pwrkey.c Input: misc - drop unnecessary calls to device_init_wakeup 2017-01-21 23:53:21 -08:00
pmic8xxx-pwrkey.c Input: misc - drop empty remove functions 2017-01-21 23:53:34 -08:00
powermate.c Input: powermate - constify usb_device_id and fix space before '[' error 2017-08-07 20:10:18 -07:00
pwm-beeper.c Input: pwm-beeper - support customized freq for SND_BELL 2017-03-07 10:39:23 -08:00
pwm-vibra.c Input: add a driver for PWM controllable vibrators 2017-09-04 12:13:24 -07:00
rave-sp-pwrbutton.c Input: add RAVE SP Powerbutton driver 2018-03-08 15:34:45 -08:00
rb532_button.c MIPS: Remove all the uses of custom gpio.h 2015-09-03 12:08:02 +02:00
regulator-haptic.c locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE() 2017-10-25 11:01:08 +02:00
retu-pwrbutton.c Input: misc - drop empty remove functions 2017-01-21 23:53:34 -08:00
rk805-pwrkey.c Input: add power key driver for Rockchip RK805 PMIC 2017-07-24 17:00:55 -07:00
rotary_encoder.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
sgi_btns.c input: misc: drop owner assignment from platform_drivers 2014-10-20 16:20:40 +02:00
sirfsoc-onkey.c Input: misc - drop empty remove functions 2017-01-21 23:53:34 -08:00
soc_button_array.c Input: soc_button_array - silence -ENOENT error on Dell XPS13 9365 2017-08-20 09:30:23 -07:00
sparcspkr.c Input: sparcspkr - use platform_register/unregister_drivers() 2015-12-02 10:02:50 -08:00
tps65218-pwrbutton.c Linux 4.10-rc5 2017-01-24 12:37:43 -08:00
twl4030-pwrbutton.c mfd: twl: Move header file out of I2C realm 2017-09-04 14:41:02 +01:00
twl4030-vibra.c Input: twl4030-vibra - fix sibling-node lookup 2018-01-08 17:40:52 -08:00
twl6040-vibra.c Input: twl6040-vibra - fix child-node lookup 2018-01-08 17:40:55 -08:00
uinput.c vfs: do bulk POLL* -> EPOLL* replacement 2018-02-11 14:34:03 -08:00
wistron_btns.c Input: wistron_btns - remove use of sparse_keymap_free 2017-03-09 10:06:12 -08:00
wm831x-on.c Input: wm831x-on - pass the IRQF_ONESHOT flag 2015-05-15 15:58:42 -07:00
xen-kbdfront.c Input: xen-kbdfront - do not advertise multi-touch pressure support 2018-01-02 09:41:47 -08:00
yealink.c Input: inline macros for MODULE_LICENSE, etc 2018-01-17 09:52:22 -08:00
yealink.h Input: yealink - define packet offset __be16 instead of u16 2017-04-10 20:41:41 -07:00