mirror of https://gitee.com/openkylin/linux.git
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> |
||
---|---|---|
.. | ||
.gitignore | ||
Makefile | ||
adi_64.c | ||
apc.c | ||
asm-offsets.c | ||
audit.c | ||
auxio_32.c | ||
auxio_64.c | ||
btext.c | ||
central.c | ||
cherrs.S | ||
chmc.c | ||
compat_audit.c | ||
cpu.c | ||
cpumap.c | ||
cpumap.h | ||
devices.c | ||
ds.c | ||
dtlb_miss.S | ||
dtlb_prot.S | ||
ebus.c | ||
entry.S | ||
entry.h | ||
etrap_32.S | ||
etrap_64.S | ||
fpu_traps.S | ||
ftrace.c | ||
getsetcc.S | ||
head_32.S | ||
head_64.S | ||
helpers.S | ||
hvapi.c | ||
hvcalls.S | ||
hvtramp.S | ||
idprom.c | ||
iommu-common.c | ||
iommu.c | ||
iommu_common.h | ||
ioport.c | ||
irq.h | ||
irq_32.c | ||
irq_64.c | ||
itlb_miss.S | ||
ivec.S | ||
jump_label.c | ||
kernel.h | ||
kgdb_32.c | ||
kgdb_64.c | ||
kprobes.c | ||
kstack.h | ||
ktlb.S | ||
ldc.c | ||
led.c | ||
leon_kernel.c | ||
leon_pci.c | ||
leon_pci_grpci1.c | ||
leon_pci_grpci2.c | ||
leon_pmc.c | ||
leon_smp.c | ||
mdesc.c | ||
misctrap.S | ||
module.c | ||
nmi.c | ||
of_device_32.c | ||
of_device_64.c | ||
of_device_common.c | ||
of_device_common.h | ||
pci.c | ||
pci_common.c | ||
pci_fire.c | ||
pci_impl.h | ||
pci_msi.c | ||
pci_psycho.c | ||
pci_sabre.c | ||
pci_schizo.c | ||
pci_sun4v.c | ||
pci_sun4v.h | ||
pci_sun4v_asm.S | ||
pcic.c | ||
pcr.c | ||
perf_event.c | ||
pmc.c | ||
power.c | ||
process_32.c | ||
process_64.c | ||
prom.h | ||
prom_32.c | ||
prom_64.c | ||
prom_common.c | ||
prom_irqtrans.c | ||
psycho_common.c | ||
psycho_common.h | ||
ptrace_32.c | ||
ptrace_64.c | ||
reboot.c | ||
rtrap_32.S | ||
rtrap_64.S | ||
sbus.c | ||
setup_32.c | ||
setup_64.c | ||
signal32.c | ||
signal_32.c | ||
signal_64.c | ||
sigutil.h | ||
sigutil_32.c | ||
sigutil_64.c | ||
smp_32.c | ||
smp_64.c | ||
sparc_ksyms.c | ||
spiterrs.S | ||
sstate.c | ||
stacktrace.c | ||
starfire.c | ||
sun4d_irq.c | ||
sun4d_smp.c | ||
sun4m_irq.c | ||
sun4m_smp.c | ||
sun4v_ivec.S | ||
sun4v_mcd.S | ||
sun4v_tlb_miss.S | ||
sys32.S | ||
sys_sparc32.c | ||
sys_sparc_32.c | ||
sys_sparc_64.c | ||
syscalls.S | ||
sysfs.c | ||
systbls.h | ||
systbls_32.S | ||
systbls_64.S | ||
time_32.c | ||
time_64.c | ||
trampoline_32.S | ||
trampoline_64.S | ||
traps_32.c | ||
traps_64.c | ||
tsb.S | ||
ttable_32.S | ||
ttable_64.S | ||
una_asm_32.S | ||
una_asm_64.S | ||
unaligned_32.c | ||
unaligned_64.c | ||
uprobes.c | ||
urtt_fill.S | ||
utrap.S | ||
vdso.c | ||
vio.c | ||
viohs.c | ||
visemul.c | ||
vmlinux.lds.S | ||
windows.c | ||
winfixup.S | ||
wof.S | ||
wuf.S |