a86854d0c5
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc(). This patch replaces cases of: devm_kzalloc(handle, a * b, gfp) with: devm_kcalloc(handle, a * b, gfp) as well as handling cases of: devm_kzalloc(handle, a * b * c, gfp) with: devm_kzalloc(handle, array3_size(a, b, c), gfp) as it's slightly less ugly than: devm_kcalloc(handle, array_size(a, b), c, gfp) This does, however, attempt to ignore constant size factors like: devm_kzalloc(handle, 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. Some manual whitespace fixes were needed in this patch, as Coccinelle really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...". The Coccinelle script used for this was: // Fix redundant parens around sizeof(). @@ expression HANDLE; type TYPE; expression THING, E; @@ ( devm_kzalloc(HANDLE, - (sizeof(TYPE)) * E + sizeof(TYPE) * E , ...) | devm_kzalloc(HANDLE, - (sizeof(THING)) * E + sizeof(THING) * E , ...) ) // Drop single-byte sizes and redundant parens. @@ expression HANDLE; expression COUNT; typedef u8; typedef __u8; @@ ( devm_kzalloc(HANDLE, - sizeof(u8) * (COUNT) + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(__u8) * (COUNT) + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(char) * (COUNT) + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(unsigned char) * (COUNT) + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(u8) * COUNT + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(__u8) * COUNT + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(char) * COUNT + COUNT , ...) | devm_kzalloc(HANDLE, - sizeof(unsigned char) * COUNT + COUNT , ...) ) // 2-factor product with sizeof(type/expression) and identifier or constant. @@ expression HANDLE; type TYPE; expression THING; identifier COUNT_ID; constant COUNT_CONST; @@ ( - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * (COUNT_ID) + COUNT_ID, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * COUNT_ID + COUNT_ID, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * (COUNT_CONST) + COUNT_CONST, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * COUNT_CONST + COUNT_CONST, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * (COUNT_ID) + COUNT_ID, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * COUNT_ID + COUNT_ID, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * (COUNT_CONST) + COUNT_CONST, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * COUNT_CONST + COUNT_CONST, sizeof(THING) , ...) ) // 2-factor product, only identifiers. @@ expression HANDLE; identifier SIZE, COUNT; @@ - devm_kzalloc + devm_kcalloc (HANDLE, - SIZE * COUNT + COUNT, SIZE , ...) // 3-factor product with 1 sizeof(type) or sizeof(expression), with // redundant parens removed. @@ expression HANDLE; expression THING; identifier STRIDE, COUNT; type TYPE; @@ ( devm_kzalloc(HANDLE, - sizeof(TYPE) * (COUNT) * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE) * (COUNT) * STRIDE + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE) * COUNT * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE) * COUNT * STRIDE + array3_size(COUNT, STRIDE, sizeof(TYPE)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING) * (COUNT) * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING) * (COUNT) * STRIDE + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING) * COUNT * (STRIDE) + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING) * COUNT * STRIDE + array3_size(COUNT, STRIDE, sizeof(THING)) , ...) ) // 3-factor product with 2 sizeof(variable), with redundant parens removed. @@ expression HANDLE; expression THING1, THING2; identifier COUNT; type TYPE1, TYPE2; @@ ( devm_kzalloc(HANDLE, - sizeof(TYPE1) * sizeof(TYPE2) * COUNT + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING1) * sizeof(THING2) * COUNT + array3_size(COUNT, sizeof(THING1), sizeof(THING2)) , ...) | devm_kzalloc(HANDLE, - sizeof(THING1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(THING1), sizeof(THING2)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE1) * sizeof(THING2) * COUNT + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2)) , ...) | devm_kzalloc(HANDLE, - sizeof(TYPE1) * sizeof(THING2) * (COUNT) + array3_size(COUNT, sizeof(TYPE1), sizeof(THING2)) , ...) ) // 3-factor product, only identifiers, with redundant parens removed. @@ expression HANDLE; identifier STRIDE, SIZE, COUNT; @@ ( devm_kzalloc(HANDLE, - (COUNT) * STRIDE * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - COUNT * (STRIDE) * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - COUNT * STRIDE * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - (COUNT) * (STRIDE) * SIZE + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - COUNT * (STRIDE) * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - (COUNT) * STRIDE * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - (COUNT) * (STRIDE) * (SIZE) + array3_size(COUNT, STRIDE, SIZE) , ...) | devm_kzalloc(HANDLE, - 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 HANDLE; expression E1, E2, E3; constant C1, C2, C3; @@ ( devm_kzalloc(HANDLE, C1 * C2 * C3, ...) | devm_kzalloc(HANDLE, - (E1) * E2 * E3 + array3_size(E1, E2, E3) , ...) | devm_kzalloc(HANDLE, - (E1) * (E2) * E3 + array3_size(E1, E2, E3) , ...) | devm_kzalloc(HANDLE, - (E1) * (E2) * (E3) + array3_size(E1, E2, E3) , ...) | devm_kzalloc(HANDLE, - 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 HANDLE; expression THING, E1, E2; type TYPE; constant C1, C2, C3; @@ ( devm_kzalloc(HANDLE, sizeof(THING) * C2, ...) | devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...) | devm_kzalloc(HANDLE, C1 * C2 * C3, ...) | devm_kzalloc(HANDLE, C1 * C2, ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * (E2) + E2, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(TYPE) * E2 + E2, sizeof(TYPE) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * (E2) + E2, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - sizeof(THING) * E2 + E2, sizeof(THING) , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - (E1) * E2 + E1, E2 , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - (E1) * (E2) + E1, E2 , ...) | - devm_kzalloc + devm_kcalloc (HANDLE, - E1 * E2 + E1, E2 , ...) ) Signed-off-by: Kees Cook <keescook@chromium.org> |
||
---|---|---|
.. | ||
devres.c | ||
gpio-74x164.c | ||
gpio-74xx-mmio.c | ||
gpio-104-dio-48e.c | ||
gpio-104-idi-48.c | ||
gpio-104-idio-16.c | ||
gpio-adnp.c | ||
gpio-adp5520.c | ||
gpio-adp5588.c | ||
gpio-altera-a10sr.c | ||
gpio-altera.c | ||
gpio-amd8111.c | ||
gpio-amdpt.c | ||
gpio-arizona.c | ||
gpio-aspeed.c | ||
gpio-ath79.c | ||
gpio-bcm-kona.c | ||
gpio-bd9571mwv.c | ||
gpio-brcmstb.c | ||
gpio-bt8xx.c | ||
gpio-clps711x.c | ||
gpio-crystalcove.c | ||
gpio-cs5535.c | ||
gpio-da9052.c | ||
gpio-da9055.c | ||
gpio-davinci.c | ||
gpio-dln2.c | ||
gpio-dwapb.c | ||
gpio-eic-sprd.c | ||
gpio-em.c | ||
gpio-ep93xx.c | ||
gpio-exar.c | ||
gpio-f7188x.c | ||
gpio-ftgpio010.c | ||
gpio-ge.c | ||
gpio-gpio-mm.c | ||
gpio-grgpio.c | ||
gpio-hlwd.c | ||
gpio-htc-egpio.c | ||
gpio-ich.c | ||
gpio-ingenic.c | ||
gpio-intel-mid.c | ||
gpio-iop.c | ||
gpio-it87.c | ||
gpio-janz-ttl.c | ||
gpio-kempld.c | ||
gpio-ks8695.c | ||
gpio-loongson1.c | ||
gpio-loongson.c | ||
gpio-lp873x.c | ||
gpio-lp3943.c | ||
gpio-lp87565.c | ||
gpio-lpc18xx.c | ||
gpio-lpc32xx.c | ||
gpio-lynxpoint.c | ||
gpio-max730x.c | ||
gpio-max732x.c | ||
gpio-max3191x.c | ||
gpio-max7300.c | ||
gpio-max7301.c | ||
gpio-max77620.c | ||
gpio-mb86s7x.c | ||
gpio-mc9s08dz60.c | ||
gpio-mc33880.c | ||
gpio-menz127.c | ||
gpio-merrifield.c | ||
gpio-ml-ioh.c | ||
gpio-mm-lantiq.c | ||
gpio-mmio.c | ||
gpio-mockup.c | ||
gpio-mpc8xxx.c | ||
gpio-mpc5200.c | ||
gpio-msic.c | ||
gpio-mvebu.c | ||
gpio-mxc.c | ||
gpio-mxs.c | ||
gpio-octeon.c | ||
gpio-omap.c | ||
gpio-palmas.c | ||
gpio-pca953x.c | ||
gpio-pcf857x.c | ||
gpio-pch.c | ||
gpio-pci-idio-16.c | ||
gpio-pcie-idio-24.c | ||
gpio-pisosr.c | ||
gpio-pl061.c | ||
gpio-pmic-eic-sprd.c | ||
gpio-pxa.c | ||
gpio-raspberrypi-exp.c | ||
gpio-rc5t583.c | ||
gpio-rcar.c | ||
gpio-rdc321x.c | ||
gpio-reg.c | ||
gpio-sa1100.c | ||
gpio-sch311x.c | ||
gpio-sch.c | ||
gpio-sodaville.c | ||
gpio-spear-spics.c | ||
gpio-sprd.c | ||
gpio-sta2x11.c | ||
gpio-stmpe.c | ||
gpio-stp-xway.c | ||
gpio-syscon.c | ||
gpio-tb10x.c | ||
gpio-tc3589x.c | ||
gpio-tegra186.c | ||
gpio-tegra.c | ||
gpio-thunderx.c | ||
gpio-timberdale.c | ||
gpio-tpic2810.c | ||
gpio-tps6586x.c | ||
gpio-tps65086.c | ||
gpio-tps65218.c | ||
gpio-tps65910.c | ||
gpio-tps65912.c | ||
gpio-tps68470.c | ||
gpio-ts4800.c | ||
gpio-ts4900.c | ||
gpio-ts5500.c | ||
gpio-twl4030.c | ||
gpio-twl6040.c | ||
gpio-ucb1400.c | ||
gpio-uniphier.c | ||
gpio-vf610.c | ||
gpio-viperboard.c | ||
gpio-vr41xx.c | ||
gpio-vx855.c | ||
gpio-wcove.c | ||
gpio-winbond.c | ||
gpio-wm831x.c | ||
gpio-wm8350.c | ||
gpio-wm8994.c | ||
gpio-ws16c48.c | ||
gpio-xgene-sb.c | ||
gpio-xgene.c | ||
gpio-xilinx.c | ||
gpio-xlp.c | ||
gpio-xra1403.c | ||
gpio-xtensa.c | ||
gpio-zevio.c | ||
gpio-zx.c | ||
gpio-zynq.c | ||
gpiolib-acpi.c | ||
gpiolib-devprop.c | ||
gpiolib-legacy.c | ||
gpiolib-of.c | ||
gpiolib-sysfs.c | ||
gpiolib.c | ||
gpiolib.h | ||
Kconfig | ||
Makefile |