linux_dsm_epyc7002/drivers/isdn/hisax
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
..
amd7930_fn.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
amd7930_fn.h
arcofi.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
arcofi.h
asuscom.c isdn: hisax: Fix pnp_irq's error checking for setup_asuscom 2017-11-16 22:31:15 +09:00
avm_a1.c
avm_a1p.c
avm_pci.c isdn: hisax: Fix pnp_irq's error checking for avm_pnp_setup 2017-11-16 22:31:15 +09:00
avma1_cs.c
bkm_a4t.c
bkm_a8.c
bkm_ax.h
callc.c
config.c isdn: hisax: constify pci_device_id. 2017-07-15 21:25:56 -07:00
diva.c isdn: hisax: Fix pnp_irq's error checking for setup_diva_isapnp 2017-11-16 22:31:15 +09:00
elsa_cs.c
elsa_ser.c networking: introduce and use skb_put_data() 2017-06-16 11:48:37 -04:00
elsa.c isdn: hisax: Fix pnp_irq's error checking for setup_elsa_isapnp 2017-11-16 22:31:15 +09:00
enternow_pci.c
fsm.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
fsm.h
gazel.c
hfc4s8s_l1.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
hfc4s8s_l1.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hfc_2bds0.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
hfc_2bds0.h
hfc_2bs0.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
hfc_2bs0.h
hfc_pci.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
hfc_pci.h
hfc_sx.c isdn: hisax: Fix pnp_irq's error checking for setup_hfcsx 2017-11-16 22:31:16 +09:00
hfc_sx.h
hfc_usb.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
hfc_usb.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hfcscard.c isdn: hisax: Fix pnp_irq's error checking for setup_hfcs 2017-11-16 22:31:16 +09:00
hisax_cfg.h
hisax_debug.h
hisax_fcpcipnp.c isdn: hisax: Handle return value of pnp_irq and pnp_port_start 2017-11-16 22:31:16 +09:00
hisax_fcpcipnp.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hisax_if.h
hisax_isac.c networking: introduce and use skb_put_data() 2017-06-16 11:48:37 -04:00
hisax_isac.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hisax.h isdn: Constify some function parameters 2016-12-17 21:46:35 -05:00
hscx_irq.c networking: introduce and use skb_put_data() 2017-06-16 11:48:37 -04:00
hscx.c
hscx.h
icc.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
icc.h
ipac.h
ipacx.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
ipacx.h
isac.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
isac.h
isar.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
isar.h
isdnl1.c isdn: fix misspelling of current function in string 2014-12-09 16:18:46 -05:00
isdnl1.h
isdnl2.c networking: introduce and use skb_put_data() 2017-06-16 11:48:37 -04:00
isdnl2.h
isdnl3.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
isdnl3.h
isurf.c isdn: hisax: Fix pnp_irq's error checking for setup_isurf 2017-11-16 22:31:16 +09:00
ix1_micro.c isdn: hisax: Fix pnp_irq's error checking for setup_ix1micro 2017-11-16 22:31:16 +09:00
jade_irq.c networking: introduce and use skb_put_data() 2017-06-16 11:48:37 -04:00
jade.c
jade.h
Kconfig treewide: simplify Kconfig dependencies for removed archs 2018-03-26 15:55:57 +02:00
l3_1tr6.c networking: introduce and use skb_put_data() 2017-06-16 11:48:37 -04:00
l3_1tr6.h
l3dss1.c networking: introduce and use skb_put_data() 2017-06-16 11:48:37 -04:00
l3dss1.h
l3ni1.c networking: introduce and use skb_put_data() 2017-06-16 11:48:37 -04:00
l3ni1.h
lmgr.c
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mic.c
netjet.c treewide: kmalloc() -> kmalloc_array() 2018-06-12 16:19:22 -07:00
netjet.h
niccy.c isdn: hisax: Fix pnp_irq's error checking for setup_niccy 2017-11-16 22:31:16 +09:00
nj_s.c
nj_u.c
q931.c treewide: Fix printk() message errors 2016-12-14 10:54:27 +01:00
s0box.c
saphir.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
sedlbauer_cs.c
sedlbauer.c isdn: hisax: Fix pnp_irq's error checking for setup_sedlbauer_isapnp 2017-11-16 22:31:16 +09:00
sportster.c
st5481_b.c scripts/spelling.txt: add "disble(d)" pattern and fix typo instances 2017-03-09 17:01:09 -08:00
st5481_d.c
st5481_init.c
st5481_usb.c networking: introduce and use skb_put_data() 2017-06-16 11:48:37 -04:00
st5481.h
tei.c
teleint.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
teles0.c
teles3.c isdn: hisax: Fix pnp_irq's error checking for setup_teles3 2017-11-16 22:31:16 +09:00
teles_cs.c
telespci.c
w6692.c isdn/hisax: Convert timers to use timer_setup() 2017-10-18 12:39:37 +01:00
w6692.h