linux_dsm_epyc7002/drivers/media/platform
Kees Cook 6da2ec5605 treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:

        kmalloc(a * b, gfp)

with:
        kmalloc_array(a * b, gfp)

as well as handling cases of:

        kmalloc(a * b * c, gfp)

with:

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

as it's slightly less ugly than:

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

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

        kmalloc(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 tools/ directory was manually excluded, since it has its own
implementation of kmalloc().

The Coccinelle script used for this was:

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

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

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

(
  kmalloc(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  kmalloc(
-	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;
@@

(
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kmalloc
+ kmalloc_array
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

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

- kmalloc
+ kmalloc_array
  (
-	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;
@@

(
  kmalloc(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kmalloc(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kmalloc(
-	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;
@@

(
  kmalloc(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kmalloc(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kmalloc(
-	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;
@@

(
  kmalloc(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kmalloc(
-	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;
@@

(
  kmalloc(C1 * C2 * C3, ...)
|
  kmalloc(
-	(E1) * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	(E1) * (E2) * E3
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	(E1) * (E2) * (E3)
+	array3_size(E1, E2, E3)
  , ...)
|
  kmalloc(
-	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;
@@

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

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
am437x media: Remove depends on HAS_DMA in case of platform dependency 2018-05-28 16:17:08 -04:00
atmel media: Remove depends on HAS_DMA in case of platform dependency 2018-05-28 16:17:08 -04:00
cadence media: v4l: cadence: Add Cadence MIPI-CSI2 TX driver 2018-05-17 06:22:08 -04:00
cec-gpio media: cec-gpio: use GPIOD_OUT_HIGH_OPEN_DRAIN 2018-05-09 16:15:06 -04:00
coda media: coda: set colorimetry on coded queue 2018-05-09 16:23:33 -04:00
davinci media: Remove depends on HAS_DMA in case of platform dependency 2018-05-28 16:17:08 -04:00
exynos4-is media: include/media: fix missing | operator when setting cfg 2018-05-05 09:01:22 -04:00
exynos-gsc media updates for v4.16-rc1 2018-02-06 11:27:48 -08:00
marvell-ccic media: marvel-ccic: mmp: select VIDEOBUF2_VMALLOC/DMA_CONTIG 2018-06-05 09:48:50 -04:00
meson media: platform: Add Amlogic Meson AO CEC Controller driver 2017-08-09 10:45:26 -04:00
mtk-jpeg media: vcodec: fix ptr_ret.cocci warnings 2018-05-09 15:58:30 -04:00
mtk-mdp License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mtk-vcodec media: mtk-vcodec: Always signal source change event on format change 2018-02-26 07:41:36 -05:00
mtk-vpu media: mtk-vpu: add description for wdt fields at struct mtk_vpu 2017-11-30 04:19:00 -05:00
omap media: omap2: fix compile-testing with FB_OMAP2=m 2018-06-06 14:37:51 -04:00
omap3isp media: omap3isp: Don't use GFP_DMA 2018-05-09 16:38:38 -04:00
qcom remoteproc updates for v4.17 2018-04-10 12:09:27 -07:00
rcar-vin media: Remove depends on HAS_DMA in case of platform dependency 2018-05-28 16:17:08 -04:00
rockchip/rga media: rca: declare formats var as static 2018-03-23 06:28:41 -04:00
s3c-camif media: s3c-camif: fix out-of-bounds array access 2018-03-06 07:29:04 -05:00
s5p-cec media: s5p-cec: add NACK detection support 2017-09-23 07:29:30 -04:00
s5p-g2d media: platform: make video_device const 2017-08-27 08:44:30 -04:00
s5p-jpeg media: s5p-jpeg: don't return a value on a void function 2018-05-04 08:58:22 -04:00
s5p-mfc media: s5p-mfc: fix two sparse warnings 2018-05-25 15:31:00 -04:00
soc_camera media: Remove depends on HAS_DMA in case of platform dependency 2018-05-28 16:17:08 -04:00
sti media: Remove depends on HAS_DMA in case of platform dependency 2018-05-28 16:17:08 -04:00
stm32 media: stm32-dcmi: add JPEG support 2018-03-21 11:53:09 -04:00
tegra-cec media: tegra-cec: reset rx_buf_cnt when start bit detected 2018-03-05 07:46:24 -05:00
ti-vpe media: v4l2-async: simplify v4l2_async_subdev structure 2017-12-29 07:14:28 -05:00
vimc media: vimc: use correct subdev functions 2018-02-26 09:31:41 -05:00
vivid treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
vsp1 media: vsp1: Move video configuration to a cached dlb 2018-05-25 19:05:46 -04:00
xilinx media: xilinx: regroup caps on querycap 2018-05-11 11:25:06 -04:00
fsl-viu.c media: platform: fix some 64-bits warnings 2018-04-17 05:50:00 -04:00
Kconfig media: m2m-deinterlace: Remove DMA_ENGINE dependency 2018-05-28 16:20:25 -04:00
m2m-deinterlace.c media updates for v4.16-rc1 2018-02-06 11:27:48 -08:00
Makefile media: v4l: cadence: Add Cadence MIPI-CSI2 RX driver 2018-05-16 11:12:21 -04:00
mx2_emmaprp.c media: annotate ->poll() instances 2017-11-27 16:20:06 -05:00
pxa_camera.c media: pxa_camera: ignore -ENOIOCTLCMD from v4l2_subdev_call for s_power 2018-06-05 09:50:20 -04:00
rcar_drif.c media: rcar_drif: fix error return code in rcar_drif_alloc_dmachannels() 2018-02-26 07:43:29 -05:00
rcar_fdp1.c media: drivers: remove "/**" from non-kernel-doc comments 2017-11-30 04:19:03 -05:00
rcar_jpu.c media: rcar_jpu: Add missing clk_disable_unprepare() on error in jpu_open() 2018-05-11 11:23:54 -04:00
rcar-fcp.c v4l: rcar-fcp: Add an API to retrieve the FCP device 2017-06-09 12:25:36 +01:00
renesas-ceu.c media: renesas-ceu: fix compiler warning 2018-05-25 15:33:34 -04:00
sh_veu.c media: platform: sh_veu: use 64-bit arithmetic instead of 32-bit 2018-02-26 08:09:48 -05:00
sh_vou.c media: replace all <spaces><tab> occurrences 2018-01-04 13:15:05 -05:00
via-camera.c media: platform: Use gpio_is_valid() 2018-05-09 16:17:15 -04:00
via-camera.h media: fix usage of whitespaces and on indentation 2018-01-04 13:12:01 -05:00
video-mux.c media: platform: video-mux: propagate format from sink to source 2018-05-04 15:56:15 -04:00
vim2m.c media: drivers: remove "/**" from non-kernel-doc comments 2017-11-30 04:19:03 -05:00