linux/drivers/i2c/busses
Kees Cook 6396bb2215 treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:

        kzalloc(a * b, gfp)

with:
        kcalloc(a * b, gfp)

as well as handling cases of:

        kzalloc(a * b * c, gfp)

with:

        kzalloc(array3_size(a, b, c), gfp)

as it's slightly less ugly than:

        kzalloc_array(array_size(a, b), c, gfp)

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

        kzalloc(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.

The Coccinelle script used for this was:

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

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

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

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

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

(
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

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

- kzalloc
+ kcalloc
  (
-	SIZE * COUNT
+	COUNT, SIZE
  , ...)

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

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

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

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

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

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

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

(
  kzalloc(sizeof(THING) * C2, ...)
|
  kzalloc(sizeof(TYPE) * C2, ...)
|
  kzalloc(C1 * C2 * C3, ...)
|
  kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (E2)
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * E2
+	E2, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (E2)
+	E2, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * E2
+	E2, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	(E1) * E2
+	E1, E2
  , ...)
|
- kzalloc
+ kcalloc
  (
-	(E1) * (E2)
+	E1, E2
  , ...)
|
- kzalloc
+ kcalloc
  (
-	E1 * E2
+	E1, E2
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
i2c-acorn.c i2c: acorn: remove outdated path from file header 2018-01-18 00:08:20 +01:00
i2c-ali15x3.c Annotate hardware config module parameters in drivers/i2c/ 2017-04-20 12:02:32 +01:00
i2c-ali1535.c
i2c-ali1563.c
i2c-altera.c i2c: altera: Add Altera I2C Controller driver 2017-09-13 23:37:16 +02:00
i2c-amd756-s4882.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
i2c-amd756.c i2c: don't print error when adding adapter fails 2016-08-22 08:19:55 +02:00
i2c-amd8111.c
i2c-aspeed.c i2c: aspeed: Deassert reset in probe 2017-11-06 19:15:31 +01:00
i2c-at91.c i2c: busses: make i2c_adapter_quirks const 2017-08-29 22:32:47 +02:00
i2c-au1550.c
i2c-axxia.c i2c: constify i2c_adapter_quirks structures 2016-11-18 02:05:03 +01:00
i2c-bcm2835.c i2c: bcm2835: Set up the rising/falling edge delays 2018-02-22 12:11:07 +01:00
i2c-bcm-iproc.c i2c: use dev_get_drvdata() to get private data in suspend/resume hooks 2017-07-31 17:03:32 +02:00
i2c-bcm-kona.c Merge branch 'i2c/for-4.9' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux 2016-10-07 14:12:21 -07:00
i2c-brcmstb.c i2c: brcmstb: Fix START and STOP conditions 2017-03-08 18:00:49 +01:00
i2c-cadence.c i2c: use dev_get_drvdata() to get private data in suspend/resume hooks 2017-07-31 17:03:32 +02:00
i2c-cbus-gpio.c
i2c-cht-wc.c i2c-cht-wc: constify platform_device_id 2017-12-07 12:00:35 +01:00
i2c-cpm.c i2c: busses: make i2c_adapter_quirks const 2017-08-29 22:32:47 +02:00
i2c-cros-ec-tunnel.c i2c: i2c-cros-ec-tunnel: Reduce logging noise 2017-01-28 22:16:38 +01:00
i2c-davinci.c i2c: davinci: fix the cpufreq transition 2018-01-24 07:14:59 +01:00
i2c-designware-baytrail.c i2c: designware-baytrail: fix potential null pointer dereference on dev 2017-04-19 21:00:13 +02:00
i2c-designware-common.c i2c: designware: fix building driver as module 2017-11-28 10:44:19 +01:00
i2c-designware-core.h Merge branch 'i2c/for-4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux 2018-02-04 10:57:43 -08:00
i2c-designware-master.c i2c: designware: fix poll-after-enable regression 2018-05-10 12:30:20 +02:00
i2c-designware-pcidrv.c i2c: designware: MASTER mode as separated driver 2017-06-19 18:24:59 +02:00
i2c-designware-platdrv.c Merge branch 'i2c/for-4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux 2018-02-04 10:57:43 -08:00
i2c-designware-slave.c i2c: designware: Don't set SCL timings and speed mode when in slave mode 2017-11-27 18:30:13 +01:00
i2c-digicolor.c i2c: digicolor: use clk_disable_unprepare instead of clk_unprepare 2016-11-18 01:48:01 +01:00
i2c-diolan-u2c.c i2c: don't print error when adding adapter fails 2016-08-22 08:19:55 +02:00
i2c-dln2.c i2c: constify i2c_adapter_quirks structures 2016-11-18 02:05:03 +01:00
i2c-efm32.c i2c: don't print error when adding adapter fails 2016-08-22 08:19:55 +02:00
i2c-eg20t.c i2c: busses: constify i2c_algorithm structures 2017-02-09 17:06:52 +01:00
i2c-elektor.c Annotate hardware config module parameters in drivers/i2c/ 2017-04-20 12:02:32 +01:00
i2c-emev2.c i2c: emev2: Handle return value of clk_prepare_enable 2017-06-19 22:18:55 +02:00
i2c-exynos5.c i2c: exynos5: rework HSI2C_MASTER_ST_LOSE state handling 2018-02-27 13:47:28 +01:00
i2c-gpio.c i2c: gpio: Enable working over slow can_sleep GPIOs 2018-01-04 01:02:55 +01:00
i2c-highlander.c
i2c-hix5hd2.c i2c: use dev_get_drvdata() to get private data in suspend/resume hooks 2017-07-31 17:03:32 +02:00
i2c-hydra.c
i2c-i801.c i2c: i801: Restore configuration at shutdown 2018-04-11 23:08:13 +02:00
i2c-ibm_iic.c sched/headers: Prepare to move signal wakeup & sigpending methods from <linux/sched.h> into <linux/sched/signal.h> 2017-03-02 08:42:32 +01:00
i2c-ibm_iic.h
i2c-img-scb.c i2c: img-scb: Add runtime PM 2017-10-28 14:03:45 +02:00
i2c-imx-lpi2c.c i2c: imx-lpi2c: add runtime pm support 2018-01-24 07:20:30 +01:00
i2c-imx.c i2c: imx: avoid taking clk_prepare mutex in PM callbacks 2018-04-03 15:29:28 +02:00
i2c-iop3xx.c
i2c-iop3xx.h
i2c-isch.c i2c: don't print error when adding adapter fails 2016-08-22 08:19:55 +02:00
i2c-ismt.c i2c: ismt: 16-byte align the DMA buffer address 2018-01-15 21:02:43 +01:00
i2c-jz4780.c i2c: jz4780: Fix module autoload 2016-10-25 11:48:58 +02:00
i2c-kempld.c i2c: busses: make i2c_adapter const 2017-08-29 22:26:08 +02:00
i2c-lpc2k.c i2c: use dev_get_drvdata() to get private data in suspend/resume hooks 2017-07-31 17:03:32 +02:00
i2c-meson.c i2c: meson: update doc description to fix build warnings 2018-01-26 18:33:44 +01:00
i2c-mlxcpld.c i2c: busses: make i2c_adapter_quirks const 2017-08-29 22:32:47 +02:00
i2c-mpc.c i2c: mpc: always determine I2C clock prescaler at runtime 2018-01-15 19:19:55 +01:00
i2c-mt65xx.c i2c: mediatek: Enable i2c module clock before i2c registers access. 2018-01-04 00:54:02 +01:00
i2c-mv64xxx.c i2c: mv64xxx: Apply errata delay only in standard mode 2018-03-17 21:20:04 +01:00
i2c-mxs.c i2c: mxs: use true and false for boolean values 2018-01-26 18:34:50 +01:00
i2c-nforce2-s4985.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
i2c-nforce2.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
i2c-nomadik.c i2c: nomadik: constify amba_id 2017-08-29 22:35:14 +02:00
i2c-ocores.c i2c: ocores: update HDL sources URL 2018-05-29 20:14:32 +02:00
i2c-octeon-core.c i2c: octeon: Prevent error message on bus error 2018-03-02 11:11:15 +01:00
i2c-octeon-core.h i2c: octeon: Prevent error message on bus error 2018-03-02 11:11:15 +01:00
i2c-octeon-platdrv.c i2c: busses: make i2c_adapter const 2017-08-29 22:26:08 +02:00
i2c-omap.c i2c: omap: Trigger bus recovery in lockup case 2017-10-30 15:18:31 +01:00
i2c-opal.c i2c: busses: make i2c_adapter_quirks const 2017-08-29 22:32:47 +02:00
i2c-parport-light.c i2c: i2c-smbus: Use threaded irq for smbalert 2017-10-28 23:42:26 +02:00
i2c-parport.c i2c: i2c-smbus: Use threaded irq for smbalert 2017-10-28 23:42:26 +02:00
i2c-parport.h
i2c-pasemi.c
i2c-pca-isa.c Annotate hardware config module parameters in drivers/i2c/ 2017-04-20 12:02:32 +01:00
i2c-pca-platform.c i2c: pca-platform: use device_property_read_u32 2018-03-24 13:26:04 +01:00
i2c-piix4.c i2c: piix4: Use request_muxed_region 2018-03-02 11:17:23 +01:00
i2c-pmcmsp.c i2c: pmcmsp: fix error return from master_xfer 2018-05-15 09:31:19 +02:00
i2c-pnx.c i2c/busses: Convert timers to use timer_setup() 2017-10-27 15:53:30 +02:00
i2c-powermac.c i2c: busses: make i2c_adapter_quirks const 2017-08-29 22:32:47 +02:00
i2c-puv3.c i2c: busses: make i2c_algorithm const 2017-08-29 22:20:20 +02:00
i2c-pxa-pci.c ARM: pxa: move header file out of I2C realm 2017-11-28 22:49:30 +01:00
i2c-pxa.c ARM: pxa: move header file out of I2C realm 2017-11-28 22:49:30 +01:00
i2c-qup.c i2c: qup: reorganization of driver code to remove polling for qup v2 2018-03-24 13:21:02 +01:00
i2c-rcar.c i2c: rcar: fix mask value of prohibited bit 2018-03-24 14:04:38 +01:00
i2c-riic.c i2c: riic: remove clock and frequency restrictions 2017-10-27 21:39:29 +02:00
i2c-rk3x.c i2c: rk3x: add proper kerneldoc header 2018-01-18 00:34:09 +01:00
i2c-robotfuzz-osif.c i2c: busses: constify i2c_algorithm structures 2017-02-09 17:06:52 +01:00
i2c-s3c2410.c i2c: use dev_get_drvdata() to get private data in suspend/resume hooks 2017-07-31 17:03:32 +02:00
i2c-scmi.c i2c: scmi: Use standard device message logging functions 2018-03-02 11:18:55 +01:00
i2c-sh7760.c i2c: don't print error when adding adapter fails 2016-08-22 08:19:55 +02:00
i2c-sh_mobile.c i2c: sh_mobile: let r8a7790 (R-Car H2) use the new formula 2018-01-15 18:01:14 +01:00
i2c-sibyte.c
i2c-simtec.c i2c: simtec: use release_mem_region instead of release_resource 2017-08-14 21:39:21 +02:00
i2c-sirf.c i2c: busses: i2c-sirf: Fix spelling: "formular" -> "formula". 2018-02-22 12:12:35 +01:00
i2c-sis96x.c
i2c-sis630.c
i2c-sis5595.c Annotate hardware config module parameters in drivers/i2c/ 2017-04-20 12:02:32 +01:00
i2c-sprd.c i2c: sprd: Fix the i2c count issue 2018-04-27 14:12:43 +02:00
i2c-st.c i2c: use dev_get_drvdata() to get private data in suspend/resume hooks 2017-07-31 17:03:32 +02:00
i2c-stm32.h i2c: stm32: Fix copyrights 2017-12-12 23:16:04 +01:00
i2c-stm32f4.c i2c-stm32f4: remove redundant initialization of pointer reg 2018-02-27 13:51:05 +01:00
i2c-stm32f7.c i2c: i2c-stm32f7: fix no check on returned setup 2018-03-24 13:37:41 +01:00
i2c-stu300.c i2c: don't print error when adding adapter fails 2016-08-22 08:19:55 +02:00
i2c-sun6i-p2wi.c i2c: sun6i-pw2i: explicitly request exclusive reset control 2017-08-14 21:40:21 +02:00
i2c-synquacer.c i2c: add support for Socionext SynQuacer I2C controller 2018-04-04 20:33:03 +02:00
i2c-taos-evm.c i2c: taos-evm: Remove duplicate NULL check 2017-11-02 00:01:21 +01:00
i2c-tegra-bpmp.c i2c: tegra: fix spelling mistake: "contoller" -> "controller" 2017-04-21 14:04:57 +02:00
i2c-tegra.c i2c: busses: make i2c_adapter_quirks const 2017-08-29 22:32:47 +02:00
i2c-thunderx-pcidrv.c i2c: thunderx: Remove duplicate NULL check 2017-11-02 00:01:31 +01:00
i2c-tiny-usb.c i2c: i2c-tiny-usb: fix buffer not being DMA capable 2017-05-22 10:33:42 +02:00
i2c-uniphier-f.c i2c: uniphier-f: add suspend / resume support 2017-08-12 15:38:23 +02:00
i2c-uniphier.c i2c: uniphier: add suspend / resume support 2017-08-12 15:38:13 +02:00
i2c-versatile.c i2c: versatile: Make i2c_algo_bit_data const 2017-08-29 22:34:12 +02:00
i2c-via.c
i2c-viapro.c Annotate hardware config module parameters in drivers/i2c/ 2017-04-20 12:02:32 +01:00
i2c-viperboard.c i2c: viperboard: return message count on master_xfer success 2018-05-15 09:31:26 +02:00
i2c-wmt.c i2c: don't print error when adding adapter fails 2016-08-22 08:19:55 +02:00
i2c-xgene-slimpro.c i2c: xgene-slimpro: Support v2 2017-11-01 23:54:53 +01:00
i2c-xiic.c i2c: xiic: Make suspend function names consistent 2018-03-17 21:15:12 +01:00
i2c-xlp9xx.c i2c: xlp9xx: Handle NACK on DATA properly 2018-03-17 21:57:44 +01:00
i2c-xlr.c i2c: busses: constify i2c_algorithm structures 2017-02-09 17:06:52 +01:00
i2c-zx2967.c i2c: zx2967: always use the same device when printing errors 2017-06-27 23:21:00 +02:00
Kconfig platform: x86: intel_cht_int33fe: Fix dependencies 2018-05-24 18:17:00 +02:00
Makefile Merge branch 'i2c/for-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux 2018-04-07 12:36:18 -07:00
scx200_acb.c Annotate hardware config module parameters in drivers/i2c/ 2017-04-20 12:02:32 +01:00