WSL2-Linux-Kernel/drivers/staging/greybus
Kees Cook 42bc47b353 treewide: Use array_size() in vmalloc()
The vmalloc() function has no 2-factor argument form, so multiplication
factors need to be wrapped in array_size(). This patch replaces cases of:

        vmalloc(a * b)

with:
        vmalloc(array_size(a, b))

as well as handling cases of:

        vmalloc(a * b * c)

with:

        vmalloc(array3_size(a, b, c))

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

        vmalloc(4 * 1024)

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;
@@

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

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

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

(
  vmalloc(
-	sizeof(TYPE) * (COUNT_ID)
+	array_size(COUNT_ID, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(TYPE) * COUNT_ID
+	array_size(COUNT_ID, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(TYPE) * (COUNT_CONST)
+	array_size(COUNT_CONST, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(TYPE) * COUNT_CONST
+	array_size(COUNT_CONST, sizeof(TYPE))
  , ...)
|
  vmalloc(
-	sizeof(THING) * (COUNT_ID)
+	array_size(COUNT_ID, sizeof(THING))
  , ...)
|
  vmalloc(
-	sizeof(THING) * COUNT_ID
+	array_size(COUNT_ID, sizeof(THING))
  , ...)
|
  vmalloc(
-	sizeof(THING) * (COUNT_CONST)
+	array_size(COUNT_CONST, sizeof(THING))
  , ...)
|
  vmalloc(
-	sizeof(THING) * COUNT_CONST
+	array_size(COUNT_CONST, sizeof(THING))
  , ...)
)

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

  vmalloc(
-	SIZE * COUNT
+	array_size(COUNT, SIZE)
  , ...)

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

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

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

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

(
  vmalloc(C1 * C2 * C3, ...)
|
  vmalloc(
-	E1 * E2 * E3
+	array3_size(E1, E2, E3)
  , ...)
)

// And then all remaining 2 factors products when they're not all constants.
@@
expression E1, E2;
constant C1, C2;
@@

(
  vmalloc(C1 * C2, ...)
|
  vmalloc(
-	E1 * E2
+	array_size(E1, E2)
  , ...)
)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
Documentation staging: greybus: add SPDX identifiers to all greybus driver files 2017-11-11 14:46:20 +01:00
tools vfs: do bulk POLL* -> EPOLL* replacement 2018-02-11 14:34:03 -08:00
Kconfig staging: greybus: enable compile testing of arche driver 2017-05-16 13:39:16 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
TODO staging: greybus: Add TODO file with GPIO work items 2018-04-23 14:36:10 +02:00
arche-apb-ctrl.c staging: greybus: arche-apb-ctrl.c: Fix alignment should match open parenthesis 2017-12-19 14:58:30 +01:00
arche-platform.c staging: greybus: Use gpio_is_valid() 2018-04-29 15:25:52 +02:00
arche_platform.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
arpc.h staging: greybus: add SPDX identifiers to all greybus driver files 2017-11-11 14:46:20 +01:00
audio_apbridgea.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
audio_apbridgea.h staging: greybus: add SPDX identifiers to all greybus driver files 2017-11-11 14:46:20 +01:00
audio_codec.c staging: greybus: audio_codec.c: Prefer kernel type 'u32' over 'uint32_t' 2018-01-22 11:49:24 +01:00
audio_codec.h staging: greybus: Fix warning to limit chars per line 2018-04-23 15:39:08 +02:00
audio_gb.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
audio_manager.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
audio_manager.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
audio_manager_module.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
audio_manager_private.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
audio_manager_sysfs.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
audio_module.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
audio_topology.c treewide: devm_kzalloc() -> devm_kcalloc() 2018-06-12 16:19:22 -07:00
authentication.c staging: greybus: authentication.c: Fix alignment should match open parenthesis 2018-01-22 11:48:06 +01:00
bootrom.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
bundle.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
bundle.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
camera.c treewide: Use array_size() in vmalloc() 2018-06-12 16:19:22 -07:00
connection.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
connection.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
control.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
control.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
core.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
debugfs.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
es2.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
firmware.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
fw-core.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
fw-download.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
fw-management.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
gb-camera.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
gbphy.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
gbphy.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
gpio.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
greybus.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
greybus_authentication.h staging: greybus: add SPDX identifiers to all greybus driver files 2017-11-11 14:46:20 +01:00
greybus_firmware.h staging: greybus: add SPDX identifiers to all greybus driver files 2017-11-11 14:46:20 +01:00
greybus_id.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
greybus_manifest.h staging: greybus: add SPDX identifiers to all greybus driver files 2017-11-11 14:46:20 +01:00
greybus_protocols.h staging: greybus: add SPDX identifiers to all greybus driver files 2017-11-11 14:46:20 +01:00
greybus_trace.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
hd.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
hd.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
hid.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
i2c.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
interface.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
interface.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
light.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
log.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
loopback.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
manifest.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
manifest.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
module.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
module.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
operation.c treewide: setup_timer() -> timer_setup() 2017-11-21 15:57:07 -08:00
operation.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
power_supply.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
pwm.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
raw.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
sdio.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
spi.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
spilib.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
spilib.h staging: greybus: add SPDX identifiers to all greybus driver files 2017-11-11 14:46:20 +01:00
svc.c staging: greybus: Remove unused local variable 2018-05-06 19:11:23 -07:00
svc.h staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
svc_watchdog.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
uart.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
usb.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00
vibrator.c staging: greybus: Remove redundant license text 2017-11-11 14:46:21 +01:00