OpenCloudOS-Kernel/drivers/infiniband/hw/hfi1
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
..
Kconfig IB/hfi1: Remove HFI1_VERBS_31BIT_PSN option 2017-08-22 14:22:38 -04:00
Makefile IB/hfi1: Rework fault injection machinery 2018-05-09 15:53:30 -04:00
affinity.c IB/{hfi1, rdmavt, qib}: Implement CQ completion vector support 2018-05-09 15:53:30 -04:00
affinity.h IB/{hfi1, rdmavt, qib}: Implement CQ completion vector support 2018-05-09 15:53:30 -04:00
aspm.h IB/hfi1: Convert timers to use timer_setup() 2017-10-18 11:48:19 -04:00
chip.c IB/hfi1: Add bypass register defines and replace blind constants 2018-06-04 14:59:21 -06:00
chip.h IB/hfi1: Prevent LNI hang when LCB can't obtain lanes 2018-05-09 15:53:29 -04:00
chip_registers.h IB/hfi1: Add bypass register defines and replace blind constants 2018-06-04 14:59:21 -06:00
common.h IB/hfi1: Eliminate allocation while atomic 2017-10-18 10:12:59 -04:00
debugfs.c IB/hfi1: Rework fault injection machinery 2018-05-09 15:53:30 -04:00
debugfs.h RDMA/hfi1: Fix build error with debugfs disabled 2018-05-15 14:24:18 -04:00
device.c infiniband: utilize the new cdev_set_parent function 2017-03-21 06:44:33 +01:00
device.h
driver.c IB/hfi1: Add support for 16B Management Packets 2018-05-24 09:39:25 -06:00
efivar.c IB/hfi1: Check upper-case EFI variables 2017-02-19 09:18:37 -05:00
efivar.h
eprom.c IB/hfi1: Check eeprom config partition validity 2017-09-27 11:10:36 -04:00
eprom.h IB/hfi1: Add ability to read platform config from the EPROM 2016-10-02 08:42:20 -04:00
exp_rcv.c IB/hfi1: Cleanup of exp_rcv 2018-05-24 09:39:25 -06:00
exp_rcv.h IB/hfi1: Cleanup of exp_rcv 2018-05-24 09:39:25 -06:00
fault.c IB/hfi1: Rework fault injection machinery 2018-05-09 15:53:30 -04:00
fault.h IB/hfi1: Rework fault injection machinery 2018-05-09 15:53:30 -04:00
file_ops.c IB/hfi1: Fix user context tail allocation for DMA_RTAIL 2018-06-04 13:33:15 -06:00
firmware.c IB/hfi1: Fix infinite loop in 8051 command error path 2018-01-05 13:34:55 -05:00
hfi.h IB/hfi1: Rename exp_lock to exp_mutex 2018-06-04 15:25:27 -06:00
init.c IB/hfi1: Fix comment on default hdr entry size 2018-06-04 15:29:48 -06:00
intr.c IB/hfi1: Allow MgmtAllowed on B2B setups 2017-11-13 15:53:56 -05:00
iowait.h IB/hfi1: Remove dependence on qp->s_hdrwords 2018-02-01 15:24:32 -07:00
mad.c IB/hfi1: Set port number for errorinfo MAD response 2018-05-24 09:39:25 -06:00
mad.h IB/hfi1: Convert PortXmitWait/PortVLXmitWait counters to flit times 2018-02-01 15:43:30 -07:00
mmu_rb.c mm, mmu_notifier: annotate mmu notifiers with blockable invalidate callbacks 2018-01-31 17:18:38 -08:00
mmu_rb.h IB/hfi1: Don't remove RB entry when not needed. 2017-06-27 16:56:33 -04:00
opa_compat.h IB/hfi1: Document phys port state bits not used in IB 2017-08-22 14:22:37 -04:00
pcie.c 4.18 Merge window pull request 2018-06-07 13:04:07 -07:00
pio.c IB/hfi1: Reorder incorrect send context disable 2018-05-09 15:53:29 -04:00
pio.h IB/hfi1: Do not allocate PIO send contexts for VNIC 2017-11-13 15:53:57 -05:00
pio_copy.c IB/hfi1: Optimize pio_buf and send_context structs 2016-11-15 16:37:27 -05:00
platform.c IB/{hfi1, rdmavt}: Fix memory leak in hfi1_alloc_devdata() upon failure 2018-05-03 15:24:48 -04:00
platform.h IB/hfi1: Define platform_config_table_limits once 2016-12-11 15:29:42 -05:00
qp.c IB/hfi1: Fix a kernel-doc warning 2018-03-13 16:21:14 -04:00
qp.h IB/hfi1: Remove dependence on qp->s_hdrwords 2018-02-01 15:24:32 -07:00
qsfp.c IB/{hfi1, rdmavt}: Fix memory leak in hfi1_alloc_devdata() upon failure 2018-05-03 15:24:48 -04:00
qsfp.h IB/hfi1: Fetch monitor values on-demand for CableInfo query 2016-08-22 14:31:41 -04:00
rc.c IB/{rdmavt,hfi1}: Change hrtimer add to use pinned version 2018-05-24 09:39:25 -06:00
ruc.c IB/{hfi1, qib, rdmavt}: Move logic to allocate receive WQE into rdmavt 2018-05-09 15:53:30 -04:00
sdma.c treewide: Use array_size() in kvzalloc_node() 2018-06-12 16:19:22 -07:00
sdma.h IB/hfi1: Fix for early release of sdma context 2018-02-01 15:24:32 -07:00
sdma_txreq.h
sysfs.c IB/hfi1: Fix incorrect available receive user context count 2017-10-04 15:39:44 -04:00
trace.c IB/hfi1: Add 16B Management Packet trace support 2018-05-24 09:39:25 -06:00
trace.h IB/hfi1: Extend input hdr tracing for packet type 2017-09-27 11:34:13 -04:00
trace_ctxts.h treewide: remove large struct-pass-by-value from tracepoint arguments 2018-03-28 22:55:18 +02:00
trace_dbg.h IB/{hfi1, rdmavt, qib}: Implement CQ completion vector support 2018-05-09 15:53:30 -04:00
trace_ibhdrs.h IB/hfi1: Add 16B Management Packet trace support 2018-05-24 09:39:25 -06:00
trace_misc.h IB/hfi1: Add traces for TID operations 2017-06-27 16:58:13 -04:00
trace_mmu.h IB/hif1: Remove static tracing from SDMA hot path 2017-08-28 19:12:27 -04:00
trace_rc.h IB/rdmavt, IB/hfi1: Fix timer migration regressions 2017-04-05 14:45:09 -04:00
trace_rx.h IB/hfi1: Add 16B rcvhdr trace support 2018-02-01 15:43:32 -07:00
trace_tx.h IB/hif1: Remove static tracing from SDMA hot path 2017-08-28 19:12:27 -04:00
uc.c IB/{hfi1, qib, rdmavt}: Move logic to allocate receive WQE into rdmavt 2018-05-09 15:53:30 -04:00
ud.c IB/hfi1: Add support for 16B Management Packets 2018-05-24 09:39:25 -06:00
user_exp_rcv.c IB/hfi1: Rename exp_lock to exp_mutex 2018-06-04 15:25:27 -06:00
user_exp_rcv.h IB/hfi1: Move structure definitions from user_exp_rcv.c to user_exp_rcv.h 2017-08-28 19:12:22 -04:00
user_pages.c IB/hfi1: Virtual Network Interface Controller (VNIC) HW support 2017-04-20 15:19:35 -04:00
user_sdma.c Updates for 4.15 kernel merge window 2017-11-15 14:54:53 -08:00
user_sdma.h IB/hfi1: Remove unused variable 2018-06-04 14:59:21 -06:00
verbs.c IB/hfi1: Add support for 16B Management Packets 2018-05-24 09:39:25 -06:00
verbs.h IB/hfi1: Define 16B Management Packets 2018-05-24 09:39:25 -06:00
verbs_txreq.c IB/hfi1: Improve local kmem_cache_alloc performance 2017-08-28 19:12:18 -04:00
verbs_txreq.h IB/hfi1: Remove dependence on qp->s_hdrwords 2018-02-01 15:24:32 -07:00
vnic.h IB/hfi1: Add support to receive 16B bypass packets 2017-08-22 14:22:37 -04:00
vnic_main.c IB/hfi1: Do not allocate PIO send contexts for VNIC 2017-11-13 15:53:57 -05:00
vnic_sdma.c IB/hfi1: Improve local kmem_cache_alloc performance 2017-08-28 19:12:18 -04:00