linux/drivers/net/ethernet/qlogic/qed
Kees Cook fad953ce0b treewide: Use array_size() in vzalloc()
The vzalloc() function has no 2-factor argument form, so multiplication
factors need to be wrapped in array_size(). This patch replaces cases of:

        vzalloc(a * b)

with:
        vzalloc(array_size(a, b))

as well as handling cases of:

        vzalloc(a * b * c)

with:

        vzalloc(array3_size(a, b, c))

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

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

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

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

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

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

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

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

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

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

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

(
  vzalloc(C1 * C2 * C3, ...)
|
  vzalloc(
-	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;
@@

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

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
Makefile qed: Add support for tlv request processing. 2018-05-22 23:29:53 -04:00
qed_cxt.c qed: use dma_zalloc_coherent instead of allocator/memset 2018-06-04 17:28:43 -04:00
qed_cxt.h qed: Add srq core support for RoCE and iWARP 2018-06-04 17:09:54 -04:00
qed_dcbx.c qed: Add support for Unified Fabric Port. 2018-05-07 23:46:10 -04:00
qed_dcbx.h qed: Correct DCBx update scheme 2017-05-30 12:07:01 -04:00
qed_debug.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
qed_debug.h qed: Utilize FW 8.20.0.0 2017-05-18 13:21:40 -04:00
qed_dev_api.h qed: Read per queue coalesce from hardware 2017-07-27 00:05:22 -07:00
qed_dev.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
qed_fcoe.c qed: Add support for Unified Fabric Port. 2018-05-07 23:46:10 -04:00
qed_fcoe.h qed: Revise alloc/setup/free flow 2017-05-21 12:56:53 -04:00
qed_hsi.h qed*: Utilize FW 8.37.2.0 2018-06-05 10:48:09 -04:00
qed_hw.c qed*: Utilize FW 8.37.2.0 2018-06-05 10:48:09 -04:00
qed_hw.h qed*: Utilize FW 8.37.2.0 2018-06-05 10:48:09 -04:00
qed_init_fw_funcs.c qed*: Utilize FW 8.37.2.0 2018-06-05 10:48:09 -04:00
qed_init_ops.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
qed_init_ops.h
qed_int.c treewide: Fix typos in printk 2018-03-27 09:51:22 +02:00
qed_int.h qed*: HSI renaming for different types of HW 2018-01-02 13:59:15 -05:00
qed_iscsi.c qed*: Utilize FW 8.33.1.0 2018-01-02 13:59:16 -05:00
qed_iscsi.h qed: Revise alloc/setup/free flow 2017-05-21 12:56:53 -04:00
qed_iwarp.c qed*: Utilize FW 8.37.2.0 2018-06-05 10:48:09 -04:00
qed_iwarp.h qed*: Utilize FW 8.33.1.0 2018-01-02 13:59:16 -05:00
qed_l2.c treewide: Use array_size() in vzalloc() 2018-06-12 16:19:22 -07:00
qed_l2.h qed*: Utilize FW 8.37.2.0 2018-06-05 10:48:09 -04:00
qed_ll2.c qed: Fix LL2 race during connection terminate 2018-05-16 14:52:23 -04:00
qed_ll2.h qed: Add ll2 ability of opening a secondary queue 2017-10-09 10:21:26 -07:00
qed_main.c qed: Add srq core support for RoCE and iWARP 2018-06-04 17:09:54 -04:00
qed_mcp.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
qed_mcp.h qed: Add support for processing iscsi tlv request. 2018-05-22 23:29:54 -04:00
qed_mng_tlv.c qed: Add support for processing iscsi tlv request. 2018-05-22 23:29:54 -04:00
qed_ooo.c qed: Fix iWARP out of order flow 2017-10-19 12:46:43 +01:00
qed_ooo.h qed: Fix iWARP out of order flow 2017-10-19 12:46:43 +01:00
qed_ptp.c qed: Drop the 's' from num_ports_in_engines 2017-05-24 15:17:19 -04:00
qed_rdma.c qed*: Utilize FW 8.37.2.0 2018-06-05 10:48:09 -04:00
qed_rdma.h qed: Add srq core support for RoCE and iWARP 2018-06-04 17:09:54 -04:00
qed_reg_addr.h qed*: Utilize FW 8.37.2.0 2018-06-05 10:48:09 -04:00
qed_roce.c qed*: Utilize FW 8.37.2.0 2018-06-05 10:48:09 -04:00
qed_roce.h qed: Split rdma content between qed_rdma and qed_roce 2017-06-21 15:32:59 -04:00
qed_selftest.c qed: Fix PTT entry leak in the selftest error flow. 2018-03-29 14:29:55 -04:00
qed_selftest.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
qed_sp_commands.c qed: Add support for Unified Fabric Port. 2018-05-07 23:46:10 -04:00
qed_sp.h qed: Add support for Unified Fabric Port. 2018-05-07 23:46:10 -04:00
qed_spq.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2018-01-31 14:31:10 -08:00
qed_sriov.c qed* : Add new TLV to request PF to update MAC in bulletin board 2018-04-20 11:26:37 -04:00
qed_sriov.h qed*: Utilize FW 8.33.1.0 2018-01-02 13:59:16 -05:00
qed_vf.c qed* : Add new TLV to request PF to update MAC in bulletin board 2018-04-20 11:26:37 -04:00
qed_vf.h qed* : Add new TLV to request PF to update MAC in bulletin board 2018-04-20 11:26:37 -04:00
qed.h qed: Add driver infrastucture for handling mfw requests. 2018-05-22 23:29:54 -04:00