linux_old1/drivers/video/backlight
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
..
88pm860x_bl.c backlight: 88pm860x_bl: Add missing of_node_put 2015-10-15 12:06:21 +01:00
Kconfig backlight: otm3225a: Add support for ORISE OTM3225A LCD SoC 2018-04-30 10:50:44 +01:00
Makefile backlight: otm3225a: Add support for ORISE OTM3225A LCD SoC 2018-04-30 10:50:44 +01:00
aat2870_bl.c backlight: Remove .owner field for drivers using module_platform_driver 2014-08-28 14:09:48 +01:00
adp5520_bl.c backlight: adp5520: Fix error handling in adp5520_bl_probe() 2017-01-04 11:37:31 +00:00
adp8860_bl.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
adp8870_bl.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
ams369fg06.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
apple_bl.c backlight: apple_bl: Deprecate pci_get_bus_and_slot() 2017-12-20 13:47:05 +00:00
arcxcnn_bl.c backlight: Add support for Arctic Sand LED backlight driver chips 2017-04-25 09:22:23 +01:00
as3711_bl.c backlight: as3711_bl: Fix Device Tree node leaks 2018-06-11 13:40:45 +01:00
backlight.c video: backlight: Add devres versions of of_find_backlight 2018-01-29 10:34:53 -05:00
bd6107.c backlight: Remove trivial get_brightness implementations 2014-06-23 13:24:22 +01:00
corgi_lcd.c backlight: tdo24m: Fix the SPI CS between transfers 2018-01-08 09:21:57 +00:00
cr_bllcd.c backlight: cr_bllcd: Add blank line after declarations 2014-08-29 08:24:51 +01:00
da903x_bl.c backlight: Remove .owner field for drivers using module_platform_driver 2014-08-28 14:09:48 +01:00
da9052_bl.c backlight: da9052: Fix module autoload 2017-01-04 11:37:58 +00:00
ep93xx_bl.c backlight: Remove .owner field for drivers using module_platform_driver 2014-08-28 14:09:48 +01:00
generic_bl.c backlight: generic-bl: Remove DRIVER1 state 2018-04-30 13:25:14 +01:00
gpio_backlight.c backlight: gpio_backlight: Delete pdata inversion 2017-08-07 17:11:28 +01:00
hp680_bl.c
hx8357.c backlight: hx8357: remove unnecessary OOM messages 2014-04-03 16:21:10 -07:00
ili922x.c backlight: ili922x: Remove redundant variable len 2017-11-08 10:43:49 +00:00
ili9320.c backlight: ili9320: remove unnecessary OOM messages 2014-04-03 16:21:10 -07:00
ili9320.h
ipaq_micro_bl.c backlight: ipaq_micro: Fix sparse non static symbol warning 2014-07-31 10:31:22 +01:00
jornada720_bl.c backlight: jornada720: Remove 'else' after a return 2014-08-29 08:26:32 +01:00
jornada720_lcd.c backlight: jornada720: Remove 'else' after a return 2014-08-29 08:26:51 +01:00
kb3886_bl.c dmi: Mark all struct dmi_system_id instances const 2017-09-14 11:59:30 +02:00
l4f00242t03.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
lcd.c backlight: lcd: Fix race condition during register 2017-01-04 11:37:31 +00:00
ld9040.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
ld9040_gamma.h
lm3533_bl.c backlight: Remove .owner field for drivers using module_platform_driver 2014-08-28 14:09:48 +01:00
lm3630a_bl.c backlight: lm3630a: Bump REG_MAX value to 0x50 instead of 0x1F 2017-07-17 13:27:06 +01:00
lm3639_bl.c backlight: lm3639: Remove unnecessary return statements 2014-08-29 08:25:23 +01:00
lms283gf05.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
lms501kf03.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
locomolcd.c
lp855x_bl.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
lp8788_bl.c backlight: lp8788: Explicitly apply PWM config extracted from pwm_args 2016-05-17 14:45:04 +02:00
ltv350qv.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
ltv350qv.h
lv5207lp.c backlight: Remove trivial get_brightness implementations 2014-06-23 13:24:22 +01:00
max8925_bl.c backlight: max8925_bl: Fix Device Tree node lookup 2018-06-11 13:40:32 +01:00
omap1_bl.c backlight: omap1: add blank line after declarations 2014-08-29 08:27:53 +01:00
ot200_bl.c backlight: Remove .owner field for drivers using module_platform_driver 2014-08-28 14:09:48 +01:00
otm3225a.c backlight: otm3225a: Add support for ORISE OTM3225A LCD SoC 2018-04-30 10:50:44 +01:00
pandora_bl.c backlight: pandora: Stop using BL_CORE_DRIVER1 2018-04-30 13:25:14 +01:00
pcf50633-backlight.c backlight: pcf50633: Add blank line after declarations 2014-08-29 08:25:53 +01:00
platform_lcd.c backlight: Remove .owner field for drivers using module_platform_driver 2014-08-28 14:09:48 +01:00
pm8941-wled.c backlight: pm8941-wled: Add default-brightness property 2015-10-30 18:47:51 +00:00
pwm_bl.c backlight: pwm_bl: Don't use GPIOF_* with gpiod_get_direction 2018-04-30 10:50:44 +01:00
rave-sp-backlight.c backlight: Add RAVE SP backlight driver 2018-04-30 10:50:43 +01:00
s6e63m0.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
s6e63m0_gamma.h
sky81452-backlight.c backlight: sky81452: Remove unneeded use of IS_ERR_VALUE() macro 2015-08-25 08:43:21 +01:00
tdo24m.c backlight: tdo24m: Fix the SPI CS between transfers 2018-01-08 09:21:57 +00:00
tosa_bl.c backlight-tosa: Delete unnecessary assignment for the field "owner" 2016-10-06 09:27:25 +01:00
tosa_lcd.c backlight: tdo24m: Fix the SPI CS between transfers 2018-01-08 09:21:57 +00:00
tps65217_bl.c backlight: tps65217_bl: Fix Device Tree node lookup 2018-06-11 13:40:39 +01:00
vgg2432a4.c spi: Drop owner assignment from spi_drivers 2015-10-28 10:30:17 +09:00
wm831x_bl.c backlight: wm831x_bl: Add blank line after declarations 2014-08-29 08:26:21 +01:00