linux_dsm_epyc7002/drivers/net/ethernet
Kees Cook 778e1cdd81 treewide: kvzalloc() -> kvcalloc()
The kvzalloc() function has a 2-factor argument form, kvcalloc(). This
patch replaces cases of:

        kvzalloc(a * b, gfp)

with:
        kvcalloc(a * b, gfp)

as well as handling cases of:

        kvzalloc(a * b * c, gfp)

with:

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

as it's slightly less ugly than:

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

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

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

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

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

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

(
- kvzalloc
+ kvcalloc
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kvzalloc
+ kvcalloc
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kvzalloc
+ kvcalloc
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kvzalloc
+ kvcalloc
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kvzalloc
+ kvcalloc
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kvzalloc
+ kvcalloc
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kvzalloc
+ kvcalloc
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kvzalloc
+ kvcalloc
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

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

- kvzalloc
+ kvcalloc
  (
-	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;
@@

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

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

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

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

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

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
3com Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-21 16:01:54 -04:00
8390 Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-21 16:01:54 -04:00
adaptec
aeroflex
agere
alacritech
allwinner
alteon
altera
amazon net: ena: Use pci_sriov_configure_simple() to enable VFs 2018-04-24 16:47:22 -05:00
amd treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
apm
apple
aquantia net: aquantia: fix unsigned numvecs comparison with less than zero 2018-06-08 18:45:52 -04:00
arc
atheros treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
aurora
broadcom treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
brocade treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
cadence drivers: net: Remove device_node checks with of_mdiobus_register() 2018-05-16 14:20:36 -04:00
calxeda treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
cavium treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
chelsio treewide: kvzalloc() -> kvcalloc() 2018-06-12 16:19:22 -07:00
cirrus
cisco enic: fix UDP rss bits 2018-06-06 09:09:09 -04:00
cortina treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
davicom
dec
dlink
emulex be2net: Fix error detection logic for BE3 2018-05-29 10:57:25 -04:00
ezchip
faraday
freescale treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
fujitsu
hisilicon treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
hp
huawei net-next/hinic: add pci device ids for 25ge and 100ge card 2018-05-08 00:07:42 -04:00
i825xx
ibm treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
intel treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
marvell net: mvpp2: mvpp2_percpu_read_relaxed() can be static 2018-06-04 11:36:29 -04:00
mediatek
mellanox treewide: kvzalloc() -> kvcalloc() 2018-06-12 16:19:22 -07:00
micrel treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
microchip
moxa treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
mscc net: mscc: ocelot: Fix uninitialized error in ocelot_netdevice_event() 2018-06-07 16:54:39 -04:00
myricom
natsemi net/sonic: Use dma_mapping_error() 2018-05-31 14:17:33 -04:00
neterion treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
netronome treewide: kvzalloc() -> kvcalloc() 2018-06-12 16:19:22 -07:00
ni net: nixge: Address compiler warnings about signedness 2018-05-07 23:30:03 -04:00
nuvoton
nvidia treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
nxp
oki-semi treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
packetengines
pasemi treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
qlogic treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
qualcomm net: qualcomm: rmnet: Fix use after free while sending command ack 2018-06-05 10:17:05 -04:00
rdc
realtek 8139too: Remove unnecessary netif_napi_del() 2018-05-25 16:35:45 -04:00
renesas sh_eth: use DIV_ROUND_UP() in sh_eth_soft_swap() 2018-06-04 15:23:25 -04:00
rocker rocker: rocker_main: Ignore bridge VLAN events 2018-05-31 14:13:43 -04:00
samsung
seeq
sfc Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2018-06-06 18:39:49 -07:00
sgi
silan
sis
smsc
socionext treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
stmicro net: stmmac: fix build failure due to missing COMMON_CLK dependency 2018-06-08 10:59:08 -04:00
sun net: ethernet: sun: niu set correct packet size in skb 2018-05-04 13:20:46 -04:00
synopsys
tehuti
ti net: netcp: ethss: remove unnecessary pointer set to NULL 2018-06-03 10:39:48 -04:00
toshiba treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
tundra
via
wiznet
xilinx net: axienet: remove stale comment of axienet_open 2018-06-03 10:59:32 -04:00
xircom
xscale
dnet.c
dnet.h
ec_bhf.c
ethoc.c net: ethoc: Remove useless test before clk_disable_unprepare 2018-05-16 14:44:29 -04:00
fealnx.c
jme.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
jme.h
Kconfig net: ethernet: Sort Kconfig sourcing alphabetically 2018-05-21 12:14:47 -04:00
korina.c
lantiq_etop.c
Makefile net: mscc: Add initial Ocelot switch support 2018-05-15 16:41:15 -04:00
netx-eth.c