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> |
||
---|---|---|
.. | ||
88pm80x.c | ||
88pm800.c | ||
88pm805.c | ||
88pm860x-core.c | ||
88pm860x-i2c.c | ||
aat2870-core.c | ||
ab3100-core.c | ||
ab3100-otp.c | ||
ab8500-core.c | ||
ab8500-debugfs.c | ||
ab8500-gpadc.c | ||
ab8500-sysctrl.c | ||
abx500-core.c | ||
ac100.c | ||
act8945a.c | ||
adp5520.c | ||
altera-a10sr.c | ||
arizona-core.c | ||
arizona-i2c.c | ||
arizona-irq.c | ||
arizona-spi.c | ||
arizona.h | ||
as3711.c | ||
as3722.c | ||
asic3.c | ||
atmel-flexcom.c | ||
atmel-hlcdc.c | ||
atmel-smc.c | ||
axp20x-i2c.c | ||
axp20x-rsb.c | ||
axp20x.c | ||
bcm590xx.c | ||
bd9571mwv.c | ||
cros_ec_dev.c | ||
cros_ec_dev.h | ||
cros_ec_i2c.c | ||
cros_ec_spi.c | ||
cros_ec.c | ||
cs47l24-tables.c | ||
cs5535-mfd.c | ||
da903x.c | ||
da9052-core.c | ||
da9052-i2c.c | ||
da9052-irq.c | ||
da9052-spi.c | ||
da9055-core.c | ||
da9055-i2c.c | ||
da9062-core.c | ||
da9063-core.c | ||
da9063-i2c.c | ||
da9063-irq.c | ||
da9150-core.c | ||
davinci_voicecodec.c | ||
db8500-prcmu.c | ||
dbx500-prcmu-regs.h | ||
dln2.c | ||
dm355evm_msp.c | ||
exynos-lpass.c | ||
ezx-pcap.c | ||
fsl-imx25-tsadc.c | ||
hi655x-pmic.c | ||
hi6421-pmic-core.c | ||
htc-i2cpld.c | ||
htc-pasic3.c | ||
intel_msic.c | ||
intel_quark_i2c_gpio.c | ||
intel_soc_pmic_bxtwc.c | ||
intel_soc_pmic_chtdc_ti.c | ||
intel_soc_pmic_chtwc.c | ||
intel_soc_pmic_core.c | ||
intel_soc_pmic_core.h | ||
intel_soc_pmic_crc.c | ||
intel-lpss-acpi.c | ||
intel-lpss-pci.c | ||
intel-lpss.c | ||
intel-lpss.h | ||
ipaq-micro.c | ||
janz-cmodio.c | ||
jz4740-adc.c | ||
Kconfig | ||
kempld-core.c | ||
lm3533-core.c | ||
lm3533-ctrlbank.c | ||
lp873x.c | ||
lp3943.c | ||
lp8788-irq.c | ||
lp8788.c | ||
lp87565.c | ||
lpc_ich.c | ||
lpc_sch.c | ||
Makefile | ||
max8907.c | ||
max8925-core.c | ||
max8925-i2c.c | ||
max8997-irq.c | ||
max8997.c | ||
max8998-irq.c | ||
max8998.c | ||
max14577.c | ||
max77620.c | ||
max77686.c | ||
max77693.c | ||
max77843.c | ||
mc13xxx-core.c | ||
mc13xxx-i2c.c | ||
mc13xxx-spi.c | ||
mc13xxx.h | ||
mcp-core.c | ||
mcp-sa11x0.c | ||
menelaus.c | ||
menf21bmc.c | ||
mfd-core.c | ||
motorola-cpcap.c | ||
mt6397-core.c | ||
mxs-lradc.c | ||
omap-usb-host.c | ||
omap-usb-tll.c | ||
omap-usb.h | ||
palmas.c | ||
pcf50633-adc.c | ||
pcf50633-core.c | ||
pcf50633-gpio.c | ||
pcf50633-irq.c | ||
qcom_rpm.c | ||
qcom-pm8xxx.c | ||
qcom-spmi-pmic.c | ||
rave-sp.c | ||
rc5t583-irq.c | ||
rc5t583.c | ||
rdc321x-southbridge.c | ||
retu-mfd.c | ||
rk808.c | ||
rn5t618.c | ||
rt5033.c | ||
sec-core.c | ||
sec-irq.c | ||
si476x-cmd.c | ||
si476x-i2c.c | ||
si476x-prop.c | ||
sky81452.c | ||
sm501.c | ||
smsc-ece1099.c | ||
sprd-sc27xx-spi.c | ||
ssbi.c | ||
sta2x11-mfd.c | ||
stm32-lptimer.c | ||
stm32-timers.c | ||
stmpe-i2c.c | ||
stmpe-spi.c | ||
stmpe.c | ||
stmpe.h | ||
stw481x.c | ||
sun4i-gpadc.c | ||
sun6i-prcm.c | ||
syscon.c | ||
t7l66xb.c | ||
tc3589x.c | ||
tc6387xb.c | ||
tc6393xb.c | ||
ti_am335x_tscadc.c | ||
ti-lmu.c | ||
timberdale.c | ||
timberdale.h | ||
tmio_core.c | ||
tps6105x.c | ||
tps6507x.c | ||
tps6586x.c | ||
tps65010.c | ||
tps65086.c | ||
tps65090.c | ||
tps65217.c | ||
tps65218.c | ||
tps65910.c | ||
tps65911-comparator.c | ||
tps65912-core.c | ||
tps65912-i2c.c | ||
tps65912-spi.c | ||
tps68470.c | ||
tps80031.c | ||
twl4030-audio.c | ||
twl4030-irq.c | ||
twl4030-power.c | ||
twl6030-irq.c | ||
twl6040.c | ||
twl-core.c | ||
twl-core.h | ||
ucb1x00-assabet.c | ||
ucb1x00-core.c | ||
ucb1x00-ts.c | ||
ucb1400_core.c | ||
vexpress-sysreg.c | ||
viperboard.c | ||
vx855.c | ||
wl1273-core.c | ||
wm97xx-core.c | ||
wm831x-auxadc.c | ||
wm831x-core.c | ||
wm831x-i2c.c | ||
wm831x-irq.c | ||
wm831x-otp.c | ||
wm831x-spi.c | ||
wm5102-tables.c | ||
wm5110-tables.c | ||
wm8350-core.c | ||
wm8350-gpio.c | ||
wm8350-i2c.c | ||
wm8350-irq.c | ||
wm8350-regmap.c | ||
wm8400-core.c | ||
wm8994-core.c | ||
wm8994-irq.c | ||
wm8994-regmap.c | ||
wm8994.h | ||
wm8997-tables.c | ||
wm8998-tables.c |