mirror of
https://github.com/torvalds/linux.git
synced 2024-11-18 10:01:43 +00:00
6396bb2215
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> |
||
---|---|---|
.. | ||
i2c-acorn.c | ||
i2c-ali15x3.c | ||
i2c-ali1535.c | ||
i2c-ali1563.c | ||
i2c-altera.c | ||
i2c-amd756-s4882.c | ||
i2c-amd756.c | ||
i2c-amd8111.c | ||
i2c-aspeed.c | ||
i2c-at91.c | ||
i2c-au1550.c | ||
i2c-axxia.c | ||
i2c-bcm2835.c | ||
i2c-bcm-iproc.c | ||
i2c-bcm-kona.c | ||
i2c-brcmstb.c | ||
i2c-cadence.c | ||
i2c-cbus-gpio.c | ||
i2c-cht-wc.c | ||
i2c-cpm.c | ||
i2c-cros-ec-tunnel.c | ||
i2c-davinci.c | ||
i2c-designware-baytrail.c | ||
i2c-designware-common.c | ||
i2c-designware-core.h | ||
i2c-designware-master.c | ||
i2c-designware-pcidrv.c | ||
i2c-designware-platdrv.c | ||
i2c-designware-slave.c | ||
i2c-digicolor.c | ||
i2c-diolan-u2c.c | ||
i2c-dln2.c | ||
i2c-efm32.c | ||
i2c-eg20t.c | ||
i2c-elektor.c | ||
i2c-emev2.c | ||
i2c-exynos5.c | ||
i2c-gpio.c | ||
i2c-highlander.c | ||
i2c-hix5hd2.c | ||
i2c-hydra.c | ||
i2c-i801.c | ||
i2c-ibm_iic.c | ||
i2c-ibm_iic.h | ||
i2c-img-scb.c | ||
i2c-imx-lpi2c.c | ||
i2c-imx.c | ||
i2c-iop3xx.c | ||
i2c-iop3xx.h | ||
i2c-isch.c | ||
i2c-ismt.c | ||
i2c-jz4780.c | ||
i2c-kempld.c | ||
i2c-lpc2k.c | ||
i2c-meson.c | ||
i2c-mlxcpld.c | ||
i2c-mpc.c | ||
i2c-mt65xx.c | ||
i2c-mv64xxx.c | ||
i2c-mxs.c | ||
i2c-nforce2-s4985.c | ||
i2c-nforce2.c | ||
i2c-nomadik.c | ||
i2c-ocores.c | ||
i2c-octeon-core.c | ||
i2c-octeon-core.h | ||
i2c-octeon-platdrv.c | ||
i2c-omap.c | ||
i2c-opal.c | ||
i2c-parport-light.c | ||
i2c-parport.c | ||
i2c-parport.h | ||
i2c-pasemi.c | ||
i2c-pca-isa.c | ||
i2c-pca-platform.c | ||
i2c-piix4.c | ||
i2c-pmcmsp.c | ||
i2c-pnx.c | ||
i2c-powermac.c | ||
i2c-puv3.c | ||
i2c-pxa-pci.c | ||
i2c-pxa.c | ||
i2c-qup.c | ||
i2c-rcar.c | ||
i2c-riic.c | ||
i2c-rk3x.c | ||
i2c-robotfuzz-osif.c | ||
i2c-s3c2410.c | ||
i2c-scmi.c | ||
i2c-sh7760.c | ||
i2c-sh_mobile.c | ||
i2c-sibyte.c | ||
i2c-simtec.c | ||
i2c-sirf.c | ||
i2c-sis96x.c | ||
i2c-sis630.c | ||
i2c-sis5595.c | ||
i2c-sprd.c | ||
i2c-st.c | ||
i2c-stm32.h | ||
i2c-stm32f4.c | ||
i2c-stm32f7.c | ||
i2c-stu300.c | ||
i2c-sun6i-p2wi.c | ||
i2c-synquacer.c | ||
i2c-taos-evm.c | ||
i2c-tegra-bpmp.c | ||
i2c-tegra.c | ||
i2c-thunderx-pcidrv.c | ||
i2c-tiny-usb.c | ||
i2c-uniphier-f.c | ||
i2c-uniphier.c | ||
i2c-versatile.c | ||
i2c-via.c | ||
i2c-viapro.c | ||
i2c-viperboard.c | ||
i2c-wmt.c | ||
i2c-xgene-slimpro.c | ||
i2c-xiic.c | ||
i2c-xlp9xx.c | ||
i2c-xlr.c | ||
i2c-zx2967.c | ||
Kconfig | ||
Makefile | ||
scx200_acb.c |