linux_dsm_epyc7002/arch/arm/mach-omap1
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
..
include/mach License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ams-delta-fiq-handler.S ARM: OMAP1: fix ams-delta FIQ handler to work with sparse IRQ 2016-06-17 02:37:36 -07:00
ams-delta-fiq.c ARM: OMAP1: ams-delta: fix deferred_fiq handler 2018-05-03 10:06:41 -07:00
board-ams-delta.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-fsample.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-generic.c ARM: omap1: Switch to use MULTI_IRQ 2015-05-20 09:01:21 -07:00
board-h2-mmc.c mfd: tps65010: Move header file out of I2C realm 2017-08-15 08:27:22 +01:00
board-h2.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-h2.h ARM: OMAP: No need to include board-h2.h from hardware.h 2009-03-23 18:07:33 -07:00
board-h3-mmc.c mfd: tps65010: Move header file out of I2C realm 2017-08-15 08:27:22 +01:00
board-h3.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-h3.h ARM: OMAP: No need to include board-h3.h from hardware.h 2009-03-23 18:07:33 -07:00
board-htcherald.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-innovator.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-nand.c mtd: nand: Rename nand.h into rawnand.h 2017-08-13 10:11:49 +02:00
board-nokia770.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-osk.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-palmte.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-palmtt.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-palmz71.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-perseus2.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-sx1-mmc.c ARM: OMAP1: use IS_ENABLED() instead of checking for built-in or module 2016-08-26 08:41:59 -07:00
board-sx1.c ARM: omap1: add const and initconst to omap_lcd_config 2017-10-02 12:33:15 -07:00
board-sx1.h ARM: omap1: make headers more local 2015-12-01 21:52:50 +01:00
camera.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
clock_data.c ARM: OMAP1: fix USB host on 1710 2013-03-13 04:10:57 -06:00
clock.c ARM: OMAP1: clock: Fix debugfs_create_*() usage 2018-02-14 08:35:14 -08:00
clock.h ARM: OMAP: clock: Remove unused mpurate cmdline option 2017-01-24 07:20:02 -08:00
common.h ARM: OMAP: Move plat/i2c.h into mach-omap1 folder 2018-02-14 10:28:13 -08:00
devices.c ARM: OMAP1: use IS_ENABLED() instead of checking for built-in or module 2016-08-26 08:41:59 -07:00
dma.c ARM: OMAP1: DMA: Delete an unnecessary return statement in omap1_show_dma_caps() 2017-06-06 23:54:00 -07:00
fb.c ARM: OMAP1: use IS_ENABLED() instead of checking for built-in or module 2016-08-26 08:41:59 -07:00
flash.c ARM: omap1: make headers more local 2015-12-01 21:52:50 +01:00
flash.h ARM: omap1: make headers more local 2015-12-01 21:52:50 +01:00
fpga.c genirq: Remove irq argument from irq flow handlers 2015-09-16 15:47:51 +02:00
fpga.h ARM: OMAP: Fix relative includes for fpga.h 2012-10-31 15:37:14 -07:00
gpio7xx.c ARM: OMAP1: Fix randconfig builds if ARCH_OMAP15XX not selected 2015-05-21 14:50:23 -07:00
gpio15xx.c ARM: OMAP1: Fix a bunch of GPIO related section warnings after initdata got corrected 2013-10-18 10:50:51 -07:00
gpio16xx.c ARM: OMAP1: Fix randconfig builds if ARCH_OMAP15XX not selected 2015-05-21 14:50:23 -07:00
i2c.c ARM: OMAP: Move plat/i2c.h into mach-omap1 folder 2018-02-14 10:28:13 -08:00
i2c.h ARM: OMAP: Move plat/i2c.h into mach-omap1 folder 2018-02-14 10:28:13 -08:00
id.c ARM: OMAP: Split plat/cpu.h into local soc.h for mach-omap1 and mach-omap2 2012-10-18 16:23:46 -07:00
io.c ARM: OMAP: Move plat-omap/dma-omap.h to include/linux/omap-dma.h 2012-11-30 08:41:50 -08:00
iomap.h ARM: OMAP1: Remove relative includes 2012-10-31 15:37:14 -07:00
irq.c ARM: kill off set_irq_flags usage 2015-07-28 13:58:13 +02:00
Kconfig ARM: OMAP: Move dmtimer driver out of plat-omap to drivers under clocksource 2018-02-22 10:53:52 -08:00
lcd_dma.c ARM: OMAP1: Remove dma.h 2013-06-18 00:12:34 -07:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Makefile.boot ARM: 7022/1: allow to detect conflicting zreladdrs 2011-10-17 09:12:40 +01:00
mcbsp.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
mmc.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mux.c ARM: OMAP1: Fix section mismatch warnings for omap_cfg_reg 2015-05-21 14:50:23 -07:00
ocpi.c omap16xx: Removes fixme no longer needed in ocpi_enable() 2014-07-08 01:15:36 -07:00
opp_data.c ARM: OMAP: clock: split plat/clkdev_omap.h into OMAP1/2 files 2012-10-18 16:23:30 -07:00
opp.h ARM: OMAP1: Move dpll1 rates selection from config to runtime 2011-12-08 18:02:23 -08:00
pm_bus.c arm: omap1: remove boilerplate code and use USE_PM_CLK_RUNTIME_OPS 2015-05-12 23:55:38 +02:00
pm.c ARM: OMAP: Move dmtimer.h out of plat-omap 2018-02-22 10:53:06 -08:00
pm.h ARM: 6649/1: omap: use fncpy to copy the PM code functions to SRAM 2011-02-04 14:26:08 +00:00
reset.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
serial.c ARM: OMAP1: Fix randconfig builds if ARCH_OMAP15XX not selected 2015-05-21 14:50:23 -07:00
sleep.S ARM: OMAP1: Remove relative includes 2012-10-31 15:37:14 -07:00
soc.h ARM: OMAP1: Remove relative includes 2012-10-31 15:37:14 -07:00
sram-init.c ARM: OMAP: Move omap1 specific code to local sram.c 2012-10-31 10:14:14 -07:00
sram.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sram.S ARM: OMAP: Remove remaining includes for mach/io.h 2012-03-06 21:34:38 -06:00
time.c ARM/omap1/time: Migrate to new 'set-state' interface 2015-07-17 08:26:24 +05:30
timer32k.c ARM/omap1/timer32: Migrate to new 'set-state' interface 2015-07-17 08:28:39 +05:30
timer.c ARM: OMAP: Move dmtimer.h out of plat-omap 2018-02-22 10:53:06 -08:00
usb.c ARM: OMAP1: USB: delete redundant CPU class checks 2017-01-05 09:34:18 -08:00