forked from Minki/linux
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> |
||
---|---|---|
.. | ||
trace | ||
vdso32 | ||
vdso64 | ||
.gitignore | ||
align.c | ||
asm-offsets.c | ||
audit.c | ||
btext.c | ||
cacheinfo.c | ||
cacheinfo.h | ||
compat_audit.c | ||
cpu_setup_6xx.S | ||
cpu_setup_44x.S | ||
cpu_setup_fsl_booke.S | ||
cpu_setup_pa6t.S | ||
cpu_setup_power.S | ||
cpu_setup_ppc970.S | ||
cputable.c | ||
crash_dump.c | ||
crash.c | ||
dbell.c | ||
dma-iommu.c | ||
dma-swiotlb.c | ||
dma.c | ||
dt_cpu_ftrs.c | ||
eeh_cache.c | ||
eeh_dev.c | ||
eeh_driver.c | ||
eeh_event.c | ||
eeh_pe.c | ||
eeh_sysfs.c | ||
eeh.c | ||
entry_32.S | ||
entry_64.S | ||
epapr_hcalls.S | ||
epapr_paravirt.c | ||
exceptions-64e.S | ||
exceptions-64s.S | ||
fadump.c | ||
firmware.c | ||
fpu.S | ||
fsl_booke_entry_mapping.S | ||
head_8xx.S | ||
head_32.S | ||
head_40x.S | ||
head_44x.S | ||
head_64.S | ||
head_booke.h | ||
head_fsl_booke.S | ||
hw_breakpoint.c | ||
idle_6xx.S | ||
idle_book3e.S | ||
idle_book3s.S | ||
idle_e500.S | ||
idle_power4.S | ||
idle.c | ||
ima_kexec.c | ||
io-workarounds.c | ||
io.c | ||
iomap.c | ||
iommu.c | ||
irq.c | ||
isa-bridge.c | ||
jump_label.c | ||
kexec_elf_64.c | ||
kgdb.c | ||
kprobes-ftrace.c | ||
kprobes.c | ||
kvm_emul.S | ||
kvm.c | ||
l2cr_6xx.S | ||
legacy_serial.c | ||
machine_kexec_32.c | ||
machine_kexec_64.c | ||
machine_kexec_file_64.c | ||
machine_kexec.c | ||
Makefile | ||
mce_power.c | ||
mce.c | ||
misc_32.S | ||
misc_64.S | ||
misc.S | ||
module_32.c | ||
module_64.c | ||
module.c | ||
module.lds | ||
msi.c | ||
nvram_64.c | ||
of_platform.c | ||
optprobes_head.S | ||
optprobes.c | ||
paca.c | ||
pci_32.c | ||
pci_64.c | ||
pci_dn.c | ||
pci_of_scan.c | ||
pci-common.c | ||
pci-hotplug.c | ||
pmc.c | ||
ppc32.h | ||
ppc_save_regs.S | ||
proc_powerpc.c | ||
process.c | ||
prom_init_check.sh | ||
prom_init.c | ||
prom_parse.c | ||
prom.c | ||
ptrace32.c | ||
ptrace.c | ||
reloc_32.S | ||
reloc_64.S | ||
rtas_flash.c | ||
rtas_pci.c | ||
rtas-proc.c | ||
rtas-rtc.c | ||
rtas.c | ||
rtasd.c | ||
security.c | ||
setup_32.c | ||
setup_64.c | ||
setup-common.c | ||
setup.h | ||
signal_32.c | ||
signal_64.c | ||
signal.c | ||
signal.h | ||
smp-tbsync.c | ||
smp.c | ||
stacktrace.c | ||
suspend.c | ||
swsusp_32.S | ||
swsusp_64.c | ||
swsusp_asm64.S | ||
swsusp_booke.S | ||
swsusp.c | ||
sys_ppc32.c | ||
syscalls.c | ||
sysfs.c | ||
systbl_chk.c | ||
systbl_chk.sh | ||
systbl.S | ||
tau_6xx.c | ||
time.c | ||
tm.S | ||
traps.c | ||
udbg_16550.c | ||
udbg.c | ||
uprobes.c | ||
vdso.c | ||
vecemu.c | ||
vector.S | ||
vmlinux.lds.S | ||
watchdog.c |