1
0
Fork 0
alistair23-linux/drivers/net/ethernet/mellanox/mlx5/core
Kees Cook 84ca176bf5 treewide: Use array_size() in kvzalloc_node()
The kvzalloc_node() function has no 2-factor argument form, so
multiplication factors need to be wrapped in array_size(). This patch
replaces cases of:

        kvzalloc_node(a * b, gfp, node)

with:
        kvzalloc_node(array_size(a, b), gfp, node)

as well as handling cases of:

        kvzalloc_node(a * b * c, gfp, node)

with:

        kvzalloc_node(array3_size(a, b, c), gfp, node)

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

        kvzalloc_node(4 * 1024, gfp, node)

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_node(
-	(sizeof(TYPE)) * E
+	sizeof(TYPE) * E
  , ...)
|
  kvzalloc_node(
-	(sizeof(THING)) * E
+	sizeof(THING) * E
  , ...)
)

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

(
  kvzalloc_node(
-	sizeof(u8) * (COUNT)
+	COUNT
  , ...)
|
  kvzalloc_node(
-	sizeof(__u8) * (COUNT)
+	COUNT
  , ...)
|
  kvzalloc_node(
-	sizeof(char) * (COUNT)
+	COUNT
  , ...)
|
  kvzalloc_node(
-	sizeof(unsigned char) * (COUNT)
+	COUNT
  , ...)
|
  kvzalloc_node(
-	sizeof(u8) * COUNT
+	COUNT
  , ...)
|
  kvzalloc_node(
-	sizeof(__u8) * COUNT
+	COUNT
  , ...)
|
  kvzalloc_node(
-	sizeof(char) * COUNT
+	COUNT
  , ...)
|
  kvzalloc_node(
-	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_node(
-	sizeof(TYPE) * (COUNT_ID)
+	array_size(COUNT_ID, sizeof(TYPE))
  , ...)
|
  kvzalloc_node(
-	sizeof(TYPE) * COUNT_ID
+	array_size(COUNT_ID, sizeof(TYPE))
  , ...)
|
  kvzalloc_node(
-	sizeof(TYPE) * (COUNT_CONST)
+	array_size(COUNT_CONST, sizeof(TYPE))
  , ...)
|
  kvzalloc_node(
-	sizeof(TYPE) * COUNT_CONST
+	array_size(COUNT_CONST, sizeof(TYPE))
  , ...)
|
  kvzalloc_node(
-	sizeof(THING) * (COUNT_ID)
+	array_size(COUNT_ID, sizeof(THING))
  , ...)
|
  kvzalloc_node(
-	sizeof(THING) * COUNT_ID
+	array_size(COUNT_ID, sizeof(THING))
  , ...)
|
  kvzalloc_node(
-	sizeof(THING) * (COUNT_CONST)
+	array_size(COUNT_CONST, sizeof(THING))
  , ...)
|
  kvzalloc_node(
-	sizeof(THING) * COUNT_CONST
+	array_size(COUNT_CONST, sizeof(THING))
  , ...)
)

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

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

(
  kvzalloc_node(
-	sizeof(TYPE) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kvzalloc_node(
-	sizeof(TYPE) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kvzalloc_node(
-	sizeof(TYPE) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kvzalloc_node(
-	sizeof(TYPE) * COUNT * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(TYPE))
  , ...)
|
  kvzalloc_node(
-	sizeof(THING) * (COUNT) * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kvzalloc_node(
-	sizeof(THING) * (COUNT) * STRIDE
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kvzalloc_node(
-	sizeof(THING) * COUNT * (STRIDE)
+	array3_size(COUNT, STRIDE, sizeof(THING))
  , ...)
|
  kvzalloc_node(
-	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_node(
-	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kvzalloc_node(
-	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
  , ...)
|
  kvzalloc_node(
-	sizeof(THING1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kvzalloc_node(
-	sizeof(THING1) * sizeof(THING2) * (COUNT)
+	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
  , ...)
|
  kvzalloc_node(
-	sizeof(TYPE1) * sizeof(THING2) * COUNT
+	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
  , ...)
|
  kvzalloc_node(
-	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_node(
-	(COUNT) * STRIDE * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kvzalloc_node(
-	COUNT * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kvzalloc_node(
-	COUNT * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kvzalloc_node(
-	(COUNT) * (STRIDE) * SIZE
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kvzalloc_node(
-	COUNT * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kvzalloc_node(
-	(COUNT) * STRIDE * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kvzalloc_node(
-	(COUNT) * (STRIDE) * (SIZE)
+	array3_size(COUNT, STRIDE, SIZE)
  , ...)
|
  kvzalloc_node(
-	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_node(C1 * C2 * C3, ...)
|
  kvzalloc_node(
-	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;
@@

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

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
accel net/mlx5: Accel, Add TLS tx offload interface 2018-05-01 09:42:47 -04:00
diag net/mlx5: Add destination e-switch owner 2018-05-17 14:17:34 -07:00
en net/mlx5e: Receive buffer configuration 2018-05-24 14:23:33 -07:00
en_accel net/mlx5e: Avoid reset netdev stats on configuration changes 2018-05-25 16:14:28 -07:00
fpga treewide: kvzalloc() -> kvcalloc() 2018-06-12 16:19:22 -07:00
ipoib net/mlx5i: Use compilation flag in IPOIB header 2018-05-25 14:11:00 -07:00
lib treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
Kconfig net/mlx5e: fix TLS dependency 2018-05-29 10:03:40 -04:00
Makefile net/mlx5e: Receive buffer configuration 2018-05-24 14:23:33 -07:00
alloc.c IB/mlx5: Implement fragmented completion queue (CQ) 2018-02-15 00:30:03 -08:00
cmd.c net/mlx5: Fix dump_command mailbox length printed 2018-05-04 12:11:51 -07:00
cq.c net/mlx5: Fix wrongly assigned CQ reference counter 2018-03-07 15:54:36 -08:00
debugfs.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
dev.c net/mlx5: E-Switch, Reload IB interface when switching devlink modes 2018-02-23 12:36:39 -08:00
en.h net/mlx5e: RX, Enhance legacy Receive Queue memory scheme 2018-06-01 16:48:15 -07:00
en_arfs.c net/mlx5e: Increase aRFS flow tables size 2018-06-01 16:48:14 -07:00
en_common.c net/mlx5: Mkey creation command adjustments 2018-04-05 13:04:49 -06:00
en_dcbnl.c net/mlx5e: Receive buffer support for DCBX 2018-05-24 14:23:33 -07:00
en_dim.c net/mlx5e: Enable adaptive-TX moderation 2018-04-24 10:15:08 -04:00
en_ethtool.c net/mlx5e: RX, Remove HW LRO support in legacy RQ 2018-06-01 16:48:15 -07:00
en_fs.c net/mlx5e: Remove redundant vport context vlan update 2018-05-14 15:10:22 -07:00
en_fs_ethtool.c net/mlx5: Fix mlx5_add_flow_rules call with correct num of dests 2017-07-27 16:40:17 +03:00
en_main.c treewide: Use array_size() in kvzalloc_node() 2018-06-12 16:19:22 -07:00
en_rep.c net/mlx5e: Make function mlx5e_change_rep_mtu() static 2018-06-05 10:19:17 -04:00
en_rep.h net/mlx5e: Use shared table for offloaded TC eswitch flows 2018-05-17 17:48:54 -07:00
en_rx.c net/mlx5e: RX, Enhance legacy Receive Queue memory scheme 2018-06-01 16:48:15 -07:00
en_selftest.c net/mlx5e: RX, Generalise name of non-linear SKB head size 2018-06-01 16:48:14 -07:00
en_stats.c net/mlx5e: TX, Separate cachelines of xmit and completion stats 2018-06-01 16:48:15 -07:00
en_stats.h net/mlx5e: TX, Separate cachelines of xmit and completion stats 2018-06-01 16:48:15 -07:00
en_tc.c net/mlx5e: Get the number of offloaded TC rules from the correct table 2018-05-29 17:27:50 -07:00
en_tc.h net/mlx5e: Get the number of offloaded TC rules from the correct table 2018-05-29 17:27:50 -07:00
en_tx.c net/mlx5e: TX, Obsolete maintaining local copies of skb->len/data 2018-06-01 16:48:14 -07:00
en_txrx.c net/mlx5e: Avoid reset netdev stats on configuration changes 2018-05-25 16:14:28 -07:00
eq.c net/mlx5: Add FPGA QP error event 2018-05-31 15:35:38 -04:00
eswitch.c 4.18 Merge window pull request 2018-06-07 13:04:07 -07:00
eswitch.h net/mlx5e: Split offloaded eswitch TC rules for port mirroring 2018-05-25 14:11:00 -07:00
eswitch_offloads.c net/mlx5e: Split offloaded eswitch TC rules for port mirroring 2018-05-25 14:11:00 -07:00
fs_cmd.c net/mlx5: Add destination e-switch owner 2018-05-17 14:17:34 -07:00
fs_cmd.h net/mlx5: Flow steering cmd interface should get the fte when deleting 2018-03-06 22:20:15 -08:00
fs_core.c 4.18 Merge window pull request 2018-06-07 13:04:07 -07:00
fs_core.h Verbs flow counters support 2018-06-04 08:48:11 -06:00
fs_counters.c net/mlx5: Export flow counter related API 2018-06-02 07:33:53 +03:00
fw.c Merge candidates for 4.17 merge window 2018-04-06 17:35:43 -07:00
health.c {net, IB}/mlx5: Raise fatal IB event when sys error occurs 2018-02-28 12:10:32 -07:00
lag.c IB/mlx5: Fix congestion counters in LAG mode 2017-12-21 16:06:07 -07:00
mad.c
main.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-11 20:53:22 -04:00
mcg.c
mlx5_core.h net/mlx5: Free IRQs in shutdown path 2018-05-10 16:10:03 -07:00
mr.c net/mlx5: Decrease level of prints about non-existent MKEY 2018-05-04 12:11:51 -07:00
pagealloc.c net/mlx5: Avoid using multiple blank lines 2017-06-16 00:12:40 +03:00
pd.c
port.c net/mlx5e: PFC stall prevention support 2018-03-26 13:46:46 -07:00
qp.c net/mlx5: remove some extraneous spaces in indentations 2018-04-16 12:24:08 -07:00
rl.c net/mlx5: Packet pacing enhancement 2018-03-19 11:54:41 -06:00
sriov.c net/mlx5: Fix wrong indentation in enable SRIOV code 2017-09-28 07:23:10 +03:00
srq.c Updates for 4.14 kernel merge window 2017-09-03 17:49:17 -07:00
transobj.c net/mlx5: Eliminate query xsrq dead code 2018-03-30 16:16:17 -07:00
uar.c net/mlx5: Fix mlx5_get_uars_page to return error code 2018-01-12 02:01:47 +02:00
vport.c net/mlx5: Vport, Use 'kvfree()' for memory allocated by 'kvzalloc()' 2018-05-16 17:48:17 -07:00
vxlan.c net/mlx5e: Prevent possible races in VXLAN control flow 2017-12-19 23:24:03 +02:00
vxlan.h net/mlx5e: Add refcount to VXLAN structure 2017-12-19 23:24:03 +02:00
wq.c net/mlx5e: RX, Use cyclic WQ in legacy RQ 2018-06-01 16:48:15 -07:00
wq.h net/mlx5e: RX, Use cyclic WQ in legacy RQ 2018-06-01 16:48:15 -07:00