linux_dsm_epyc7002/drivers/net/ethernet/chelsio/cxgb4
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
..
clip_tbl.c treewide: kvzalloc() -> kvcalloc() 2018-06-12 16:19:22 -07:00
clip_tbl.h drivers, net, ethernet: convert clip_entry.refcnt from atomic_t to refcount_t 2017-10-22 02:22:38 +01:00
cudbg_common.c cxgb4: update dump collection logic to use compression 2018-01-19 14:56:32 -05:00
cudbg_entity.h Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-21 16:01:54 -04:00
cudbg_if.h cxgb4: update LE-TCAM collection for T6 2018-05-16 15:01:30 -04:00
cudbg_lib_common.h cxgb4: use zlib deflate to compress firmware dump 2018-01-19 14:56:32 -05:00
cudbg_lib.c cxgb4: collect SGE PF/VF queue map 2018-05-18 13:54:10 -04:00
cudbg_lib.h cxgb4: collect PCIe configuration logs 2017-12-08 14:31:50 -05:00
cudbg_zlib.c cxgb4: properly initialize variables 2018-01-24 10:56:59 -05:00
cudbg_zlib.h cxgb4: enable ZLIB_DEFLATE when building cxgb4 2018-01-24 10:56:59 -05:00
cxgb4_cudbg.c cxgb4: collect SGE PF/VF queue map 2018-05-18 13:54:10 -04:00
cxgb4_cudbg.h cxgb4: collect hardware dump in second kernel 2018-05-14 13:46:05 -04:00
cxgb4_dcb.c cxgb4: do DCB state reset in couple of places 2017-09-25 20:28:14 -07:00
cxgb4_dcb.h cxgb4: do DCB state reset in couple of places 2017-09-25 20:28:14 -07:00
cxgb4_debugfs.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
cxgb4_debugfs.h
cxgb4_ethtool.c cxgb4/cxgb4vf: link management changes for new SFP 2018-05-25 14:56:10 -04:00
cxgb4_fcoe.c
cxgb4_fcoe.h
cxgb4_filter.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-21 16:01:54 -04:00
cxgb4_filter.h cxgb4: add support to create hash-filters via tc-flower offload 2017-11-01 22:06:03 +09:00
cxgb4_main.c treewide: kvzalloc() -> kvcalloc() 2018-06-12 16:19:22 -07:00
cxgb4_ptp.c cxgb4: ptp_clock_register() returns error pointers 2017-07-14 08:18:51 -07:00
cxgb4_ptp.h cxgb4: time stamping interface for PTP 2017-07-05 09:21:54 +01:00
cxgb4_tc_flower.c cxgb4: add tc flower match support for tunnel VNI 2018-05-14 22:50:15 -04:00
cxgb4_tc_flower.h cxgb4: convert flower table to use rhashtable 2017-11-01 22:06:03 +09:00
cxgb4_tc_u32_parse.h
cxgb4_tc_u32.c treewide: kvzalloc() -> kvcalloc() 2018-06-12 16:19:22 -07:00
cxgb4_tc_u32.h net: sched: push cls related args into cls_common structure 2017-08-07 09:42:37 -07:00
cxgb4_uld.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
cxgb4_uld.h cxgb4: LLD driver changes to support TLS 2018-03-31 23:37:32 -04:00
cxgb4.h cxgb4/cxgb4vf: Notify link changes to OS-dependent code 2018-05-25 15:10:07 -04:00
l2t.c cxgb4: add tc flower match support for tunnel VNI 2018-05-14 22:50:15 -04:00
l2t.h
Makefile cxgb4: Add support to initialise/read SRQ entries 2018-03-22 11:59:11 -04:00
sched.c cxgb4: fix memory leak 2017-09-05 14:27:50 -07:00
sched.h cxgb4: increase max tx rate limit to 100 Gbps 2018-03-09 12:57:35 -05:00
sge.c treewide: kzalloc_node() -> kcalloc_node() 2018-06-12 16:19:22 -07:00
smt.c cxgb4: introduce SMT ops to prepare for SMAC rewrite support 2017-10-20 13:06:53 +01:00
smt.h cxgb4: introduce SMT ops to prepare for SMAC rewrite support 2017-10-20 13:06:53 +01:00
srq.c libcxgb,cxgb4: use __skb_put_zero to simplfy code 2018-04-30 11:53:48 -04:00
srq.h cxgb4: Add support to initialise/read SRQ entries 2018-03-22 11:59:11 -04:00
t4_chip_type.h cxgb4: clean up init_one 2018-05-25 14:59:38 -04:00
t4_hw.c cxgb4: Add FORCE_PAUSE bit to 32 bit port caps 2018-05-31 15:23:26 -04:00
t4_hw.h cxgb4: RSS table is 4k for T6 2017-12-19 14:14:19 -05:00
t4_msg.h cxgb4: enable inner header checksum calculation 2018-05-11 16:11:50 -04:00
t4_pci_id_tbl.h cxgb4: Add new T6 device ids 2018-05-23 15:28:22 -04:00
t4_regs.h cxgb4: update LE-TCAM collection for T6 2018-05-16 15:01:30 -04:00
t4_tcb.h cxgb4: add support to delete hash filter 2017-11-01 22:06:03 +09:00
t4_values.h cxgb4: Update IngPad and IngPack values 2017-03-22 10:53:49 -07:00
t4fw_api.h cxgb4: Add FORCE_PAUSE bit to 32 bit port caps 2018-05-31 15:23:26 -04:00
t4fw_version.h cxgb4: update latest firmware version supported 2018-05-03 12:52:32 -04:00