linux/drivers/net/wireless/ath/ath10k
Kees Cook 6396bb2215 treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:

        kzalloc(a * b, gfp)

with:
        kcalloc(a * b, gfp)

as well as handling cases of:

        kzalloc(a * b * c, gfp)

with:

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

as it's slightly less ugly than:

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

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

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

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

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

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

(
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_ID)
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_ID
+	COUNT_ID, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * (COUNT_CONST)
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(TYPE) * COUNT_CONST
+	COUNT_CONST, sizeof(TYPE)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_ID)
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_ID
+	COUNT_ID, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * (COUNT_CONST)
+	COUNT_CONST, sizeof(THING)
  , ...)
|
- kzalloc
+ kcalloc
  (
-	sizeof(THING) * COUNT_CONST
+	COUNT_CONST, sizeof(THING)
  , ...)
)

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

- kzalloc
+ kcalloc
  (
-	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;
@@

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

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

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

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

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

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 16:19:22 -07:00
..
ahb.c ath10k: remove useless test before clk_disable_unprepare 2018-05-25 13:02:56 +03:00
ahb.h
bmi.c ath10k: update copyright year 2017-12-27 12:22:01 +02:00
bmi.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00
ce.c ath10k: enable SRRI/DRRI support on ddr for WCN3990 2018-04-24 09:04:21 +03:00
ce.h ath10k: enable SRRI/DRRI support on ddr for WCN3990 2018-04-24 09:04:21 +03:00
core.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2018-06-06 18:39:49 -07:00
core.h ath10k: DFS Host Confirmation 2018-05-25 13:15:31 +03:00
coredump.c ath10k: add memory dump support for QCA9888 and QCA99X0 2018-05-25 12:46:05 +03:00
coredump.h ath10k: add memory dump support QCA9984 2018-03-29 11:54:32 +03:00
debug.c ath10k: fix kernel panic while reading tpc_stats 2018-04-27 14:33:28 +03:00
debug.h ath10k: debugfs support to get final TPC stats for 10.4 variants 2018-03-26 18:08:56 +03:00
debugfs_sta.c ath10k: fix information leak in debugfs 2018-04-27 14:24:25 +03:00
hif.h ath10k: add support to get target info from hif ops 2018-04-19 18:52:51 +03:00
htc.c ath10k: add HTC services for WCN3990 2018-04-19 18:52:12 +03:00
htc.h ath10k: add HTC services for WCN3990 2018-04-19 18:52:12 +03:00
htt_rx.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
htt_tx.c ath10k: enable hw checksum for wcn3990 2018-04-24 08:57:48 +03:00
htt.c ath10k: add inlined wrappers for htt tx ops 2018-04-19 19:19:28 +03:00
htt.h ath10k: enable hw checksum for wcn3990 2018-04-24 08:57:48 +03:00
hw.c ath10k: enable SRRI/DRRI support on ddr for WCN3990 2018-04-24 09:04:21 +03:00
hw.h ath10k: hw: make consistent usage of ATH10K_FW_DIR in paths 2018-05-12 12:24:03 +03:00
Kconfig ath10k: platform driver for WCN3990 SNOC WLAN module 2018-04-19 18:51:52 +03:00
mac.c ath10k: DFS Host Confirmation 2018-05-25 13:15:31 +03:00
mac.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00
Makefile ath10k: platform driver for WCN3990 SNOC WLAN module 2018-04-19 18:51:52 +03:00
p2p.c ath10k: remove ath10k_vif_to_arvif() 2017-02-14 19:38:15 +02:00
p2p.h
pci.c ath10k: modify hif tx paddr to dma_addr_t type 2018-04-19 18:52:44 +03:00
pci.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00
rx_desc.h ath10k: replace bit shifts with the BIT() macro for rx desc bits 2018-05-12 12:25:17 +03:00
sdio.c ath10k: sdio: jump to correct label in error handling path 2018-04-27 14:39:32 +03:00
sdio.h ath10k: sdio: remove unused struct member 2017-08-31 15:14:18 +03:00
snoc.c ath10k: snoc: Remove owner assignment from platform_driver 2018-05-12 12:02:11 +03:00
snoc.h ath10k: vote for hardware resources for WCN3990 2018-04-19 18:53:03 +03:00
spectral.c ath10k: update copyright year 2017-12-27 12:22:01 +02:00
spectral.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00
swap.c ath10k: update copyright year 2017-12-27 12:22:01 +02:00
swap.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00
targaddrs.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00
testmode_i.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00
testmode.c ath10k: re-enable the firmware fallback mechanism for testmode 2018-05-14 16:44:41 +02:00
testmode.h
thermal.c ath10k: update copyright year 2017-12-27 12:22:01 +02:00
thermal.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00
trace.c
trace.h ath10k: fix use-after-free in ath10k_wmi_cmd_send_nowait 2018-03-26 18:13:03 +03:00
txrx.c ath10k: Add tx ack signal support for management frames 2018-04-19 18:47:00 +03:00
txrx.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00
usb.c ath10k: add initial USB support 2017-08-03 14:31:01 +03:00
usb.h ath10k: add initial USB support 2017-08-03 14:31:01 +03:00
wmi-ops.h ath10k: DFS Host Confirmation 2018-05-25 13:15:31 +03:00
wmi-tlv.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
wmi-tlv.h ath10k: add quiet mode support for QCA6174/QCA9377 2018-05-12 12:00:33 +03:00
wmi.c ath10k: DFS Host Confirmation 2018-05-25 13:15:31 +03:00
wmi.h ath10k: DFS Host Confirmation 2018-05-25 13:15:31 +03:00
wow.c ath10k: convert wow pattern from 802.3 to 802.11 2018-04-24 08:54:52 +03:00
wow.h ath10k: update copyright year 2017-12-27 12:22:01 +02:00