linux/drivers/leds
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
..
trigger leds: Extends disk trigger for reads and writes 2018-03-11 20:01:55 +01:00
Kconfig leds: lm3601x: Introduce the lm3601x LED driver 2018-05-23 21:44:47 +02:00
Makefile leds: lm3601x: Introduce the lm3601x LED driver 2018-05-23 21:44:47 +02:00
led-class-flash.c leds: flash: Remove checking for state < 1 in flash_strobe_store() 2016-01-04 09:57:37 +01:00
led-class.c leds: class: ensure workqueue is initialized before setting brightness 2018-05-24 22:08:26 +02:00
led-core.c leds: core: Fix regression caused by commit 2b83ff96f5 2018-01-07 13:27:07 +01:00
led-triggers.c leds: triggers: Check return value of kobject_uevent_env() 2016-09-20 10:22:10 +02:00
leds-88pm860x.c leds: 88pm860x: Use devm_led_classdev_register 2016-03-14 09:22:22 +01:00
leds-aat1290.c LED updates for 4.14 2017-09-07 14:33:13 -07:00
leds-adp5520.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-apu.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-as3645a.c leds: as3645a: Fix line over 80 characters 2018-01-08 21:28:11 +01:00
leds-asic3.c leds: drop owner assignment from platform_drivers 2014-10-20 16:20:43 +02:00
leds-bcm6328.c leds: bcm6328: fix signal source assignment for leds 4 to 7 2017-06-13 20:36:56 +02:00
leds-bcm6358.c leds: bcm6358: remove unneeded busy status check 2016-01-04 09:57:40 +01:00
leds-bd2802.c leds: bd2802: Remove work queue 2016-01-04 09:57:32 +01:00
leds-blinkm.c leds: blinkm: avoid uninitialized data use 2018-01-08 21:28:10 +01:00
leds-clevo-mail.c dmi: Mark all struct dmi_system_id instances const 2017-09-14 11:59:30 +02:00
leds-cobalt-qube.c leds: leds-cobalt-qube: Use devm_led_classdev_register 2015-11-03 08:59:09 +01:00
leds-cobalt-raq.c leds: leds-cobalt-raq: use builtin_platform_driver 2016-11-23 16:38:01 +01:00
leds-cpcap.c leds: cpcap: new driver 2017-03-29 21:02:27 +02:00
leds-cr0014114.c leds: Use struct_size() in allocation 2018-06-12 16:19:22 -07:00
leds-da903x.c leds: da903x: Use devm_led_classdev_register 2016-03-14 09:22:22 +01:00
leds-da9052.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-dac124s085.c leds: dac124d085: Remove work queue 2016-01-04 09:57:34 +01:00
leds-fsg.c leds: leds-fsg: Use devm_led_classdev_register 2015-08-28 14:06:23 +02:00
leds-gpio-register.c led: gpio: Fix possible ZERO_SIZE_PTR pointer dereferencing error. 2014-09-29 10:21:01 -07:00
leds-gpio.c leds: gpio: Allow LED to retain state at shutdown 2017-08-29 21:10:40 +02:00
leds-hp6xx.c leds: convert IDE trigger to common disk trigger 2016-06-20 09:57:56 +02:00
leds-ipaq-micro.c leds: ipaq-micro: Implement brightness_set_blocking op 2016-01-04 09:57:38 +01:00
leds-is31fl32xx.c leds: Convert to using %pOF instead of full_name 2017-08-12 23:50:07 +02:00
leds-is31fl319x.c leds: is31fl319x: 1/3/6/9-channel light effect led driver 2016-08-15 14:02:31 +02:00
leds-ktd2692.c leds: ktd2692: avoid harmless maybe-uninitialized warning 2017-01-26 21:16:38 +01:00
leds-lm355x.c leds: lm355x: Remove work queue 2016-01-04 09:57:36 +01:00
leds-lm3530.c leds: Drop owner assignment from i2c_driver 2015-08-28 14:06:02 +02:00
leds-lm3533.c leds: lm3533: constify attribute_group structure 2017-08-29 21:10:37 +02:00
leds-lm3601x.c leds: lm3601x: Introduce the lm3601x LED driver 2018-05-23 21:44:47 +02:00
leds-lm3642.c leds: lm3642: Remove work queue 2016-01-04 09:57:32 +01:00
leds-lm3692x.c leds: lm3692x: Introduce LM3692x dual string driver 2018-01-08 21:28:11 +01:00
leds-locomo.c leds: leds-locomo.c: Use devm_led_classdev_register 2015-11-03 08:59:50 +01:00
leds-lp55xx-common.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-lp55xx-common.h leds: lp55xx: Remove work queue 2016-01-04 09:57:33 +01:00
leds-lp3944.c leds: lp3944: improve wording and formatting in a comment 2016-03-14 09:22:20 +01:00
leds-lp3952.c leds: lp3952: Use 'if (ret)' pattern 2017-03-23 20:33:59 +01:00
leds-lp5521.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-lp5523.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-lp5562.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-lp8501.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-lp8788.c leds: lp8788: Use devm_led_classdev_register 2016-03-14 09:22:22 +01:00
leds-lp8860.c leds: lp8860: Various fixes to align with LED framework 2018-01-08 21:28:12 +01:00
leds-lt3593.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-max8997.c leds: max8997: Use devm_led_classdev_register 2016-03-14 09:22:23 +01:00
leds-max77693.c media: v4l2-flash-led-class: Create separate sub-devices for indicators 2017-08-26 20:26:35 -04:00
leds-mc13783.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-menf21bmc.c leds: leds-menf21bmc.c: Use devm_led_class_register 2015-11-03 08:59:52 +01:00
leds-mlxcpld.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-mlxreg.c leds: add driver for support Mellanox regmap LEDs for BMC and x86 platform 2018-02-19 21:09:20 +01:00
leds-mt6323.c leds: mt6323: Fix an off by one bug in probe 2017-03-23 20:23:57 +01:00
leds-net48xx.c leds: leds-net48xx: Use devm_led_classdev_register 2015-11-03 08:59:54 +01:00
leds-netxbig.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-nic78bx.c leds: Add user LED driver for NIC78bx device 2016-11-22 12:07:04 +01:00
leds-ns2.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-ot200.c leds: leds-ot200: Use devm_led_classdev_register 2015-11-03 08:59:13 +01:00
leds-pca955x.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-pca963x.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-pca9532.c leds: pca9532: Extend pca9532 device tree support 2017-04-19 20:27:50 +02:00
leds-pm8058.c leds: pm8058: Silence pointer to integer size warning 2017-12-01 08:57:42 +00:00
leds-powernv.c leds: powernv: Delete an error message for a failed memory allocation in powernv_led_create() 2017-08-29 21:10:39 +02:00
leds-pwm.c leds: pwm: Remove unneeded header file 2018-01-08 21:28:10 +01:00
leds-rb532.c leds: drop owner assignment from platform_drivers 2014-10-20 16:20:43 +02:00
leds-regulator.c leds: regulator: Remove work queue 2016-01-04 09:57:35 +01:00
leds-s3c24xx.c leds: s3c24xx: Use devm_led_classdev_register 2016-03-14 09:22:22 +01:00
leds-sc27xx-bltc.c leds: sc27xx: Fix return value check in sc27xx_led_probe() 2018-05-22 21:57:59 +02:00
leds-ss4200.c dmi: Mark all struct dmi_system_id instances const 2017-09-14 11:59:30 +02:00
leds-sunfire.c leds: sunfire: Use platform_register/unregister_drivers() 2016-01-04 09:57:38 +01:00
leds-syscon.c leds: syscon: Make the driver explicitly non-modular 2016-01-04 09:57:39 +01:00
leds-tca6507.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
leds-tlc591xx.c leds: tlc591xx: add missing of_node_put 2017-07-16 18:45:43 +02:00
leds-wm831x-status.c leds: wm831x-status: Use sysfs_match_string() helper 2018-05-03 21:50:13 +02:00
leds-wm8350.c leds: wm8350: Remove work queue 2016-01-04 09:57:35 +01:00
leds-wrap.c leds: leds-wrap.c: Use devm_led_classdev_register 2015-11-03 08:59:58 +01:00
leds.h leds: triggers: Allow to switch the trigger to "panic" on a kernel panic 2016-05-06 10:22:09 +02:00
uleds.c vfs: do bulk POLL* -> EPOLL* replacement 2018-02-11 14:34:03 -08:00