linux-sg2042/drivers/iio/adc
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
..
Kconfig First round of IIO fixes for the 4.17 cycle. 2018-05-09 17:08:29 +02:00
Makefile IIO: ADC: add STM32 DFSDM sigma delta ADC support 2018-01-10 10:30:12 +00:00
ad799x.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ad7266.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ad7291.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ad7298.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ad7476.c iio: adc: change license description 2018-01-30 18:33:28 +00:00
ad7766.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ad7791.c iio: adc: ad7791: implement IIO_CHAN_INFO_SAMP_FREQ 2018-03-17 20:47:21 +00:00
ad7793.c iio: ad7793: implement IIO_CHAN_INFO_SAMP_FREQ 2018-03-17 20:33:01 +00:00
ad7887.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ad7923.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ad_sigma_delta.c Merge 4.14-rc4 into staging-next 2017-10-09 09:02:35 +02:00
aspeed_adc.c iio: adc: aspeed: Fix error handling path 2018-01-14 11:01:13 +00:00
at91-sama5d2_adc.c iio: adc: at91-sama5d2_adc: fix channel configuration for differential channels 2018-04-15 20:21:33 +01:00
at91_adc.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
axp20x_adc.c iio: adc: axp20x_adc: remove !! in favor of ternary condition 2018-02-24 12:19:45 +00:00
axp288_adc.c iio: Add macro to populate struct iio_map array 2017-12-02 13:28:21 +00:00
bcm_iproc_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
berlin2-adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
cc10001_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
cpcap-adc.c iio: adc: cpcap: fix incorrect validation 2017-12-02 11:15:13 +00:00
da9150-gpadc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
dln2-adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
envelope-detector.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ep93xx_adc.c iio: ep93xx: remove redundant return value check of platform_get_resource() 2018-01-30 18:33:20 +00:00
exynos_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
fsl-imx25-gcq.c iio: adc: imx25-gcq: Fix module autoload 2017-01-10 19:54:56 +00:00
hi8435.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
hx711.c iio: hx711: fix bug in reset functionality 2018-01-08 16:03:42 +01:00
imx7d_adc.c iio: adc: fix spelling mistake: "Freeacale" -> "Freescale" 2018-05-22 18:17:57 +01:00
ina2xx-adc.c iio: adc: ina2xx: Actually align the loop with the conversion ready flag 2018-01-08 16:03:43 +01:00
lp8788_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
lpc18xx_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
lpc32xx_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ltc2471.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ltc2485.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ltc2497.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
max1027.c treewide: devm_kmalloc() -> devm_kmalloc_array() 2018-06-12 16:19:22 -07:00
max1118.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
max1363.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
max9611.c iio:adc:max9611: Drop explicit setting of the i2c module owner. 2017-09-03 18:10:25 +01:00
max11100.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
mcp320x.c iio: adc: mcp320x: Add support for mcp3550/1/3 2017-10-09 21:01:36 +01:00
mcp3422.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
men_z188_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
meson_saradc.c 1st round of IIO new device support, features and cleanup for the 4.18 cycle 2018-05-11 09:50:04 +02:00
mt6577_auxadc.c iio: adc: mt2712: Add compatible node for mt2712. 2017-09-24 16:45:38 +01:00
mxs-lradc-adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
nau7802.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
palmas_gpadc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
qcom-pm8xxx-xoadc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
qcom-spmi-iadc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
qcom-spmi-vadc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
qcom-vadc-common.c iio: adc/accel: Fix up module licenses 2017-12-02 10:39:43 +00:00
qcom-vadc-common.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
rcar-gyroadc.c iio: adc: rcar-gyroadc: Use of_device_get_match_data() helper 2017-10-09 20:50:49 +01:00
rockchip_saradc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
sd_adc_modulator.c IIO: ADC: add sigma delta modulator support 2018-01-10 10:30:09 +00:00
spear_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
stm32-adc-core.c iio: adc: stm32-adc: add support for STM32MP1 2018-05-07 18:21:00 +01:00
stm32-adc-core.h iio: stm32: Adopt SPDX identifier 2018-01-08 16:03:41 +01:00
stm32-adc.c iio: adc: stm32-adc: add support for STM32MP1 2018-05-07 18:21:00 +01:00
stm32-dfsdm-adc.c Staging/IIO patches for 4.18-rc1 2018-06-09 10:32:39 -07:00
stm32-dfsdm-core.c iio: adc: stm32-dfsdm: Add support for stm32mp1 2018-05-12 10:22:17 +01:00
stm32-dfsdm.h IIO: ADC: add stm32 DFSDM core support 2018-01-10 10:30:11 +00:00
stx104.c iio: stx104: Implement get_multiple callback 2018-03-17 16:21:27 +00:00
sun4i-gpadc-iio.c iio: adc: sun4i-gpadc: use of_device_get_match_data 2017-10-21 18:48:00 +01:00
ti-adc081c.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ti-adc084s021.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ti-adc108s102.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ti-adc128s052.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ti-adc161s626.c iio: add SPDX identifier for various drivers 2018-02-18 11:55:19 +00:00
ti-adc0832.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ti-adc12138.c iio: adc: adc12138: make array ch_to_mux static, makes object code smaller 2017-10-21 17:56:09 +01:00
ti-ads1015.c Merge 4.14-rc4 into staging-next 2017-10-09 09:02:35 +02:00
ti-ads7950.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ti-ads8688.c iio: adc: ti-ads8688: add trigger and buffer support 2018-05-12 12:00:30 +01:00
ti-tlc4541.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
ti_am335x_adc.c Drivers:iio:adc:ti_am335x_adc remove comparison to bool 2018-01-08 16:03:43 +01:00
twl4030-madc.c Merge 4.14-rc4 into staging-next 2017-10-09 09:02:35 +02:00
twl6030-gpadc.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
vf610_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
viperboard_adc.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
xilinx-xadc-core.c iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:22:25 +01:00
xilinx-xadc-events.c iio: adc: xadc: Fix coding style violations 2017-08-12 13:10:30 +01:00
xilinx-xadc.h iio: adc: xadc: Fix coding style violations 2017-08-12 13:10:30 +01:00