mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-16 20:07:31 +07: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> |
||
---|---|---|
.. | ||
reg_srcs | ||
.gitignore | ||
atom-bits.h | ||
atom-names.h | ||
atom-types.h | ||
atom.c | ||
atom.h | ||
atombios_crtc.c | ||
atombios_dp.c | ||
atombios_encoders.c | ||
atombios_i2c.c | ||
atombios.h | ||
avivod.h | ||
btc_dpm.c | ||
btc_dpm.h | ||
btcd.h | ||
cayman_blit_shaders.c | ||
cayman_blit_shaders.h | ||
ci_dpm.c | ||
ci_dpm.h | ||
ci_smc.c | ||
cik_blit_shaders.c | ||
cik_blit_shaders.h | ||
cik_reg.h | ||
cik_sdma.c | ||
cik.c | ||
cikd.h | ||
clearstate_cayman.h | ||
clearstate_ci.h | ||
clearstate_defs.h | ||
clearstate_evergreen.h | ||
clearstate_si.h | ||
cypress_dpm.c | ||
cypress_dpm.h | ||
dce3_1_afmt.c | ||
dce6_afmt.c | ||
evergreen_blit_shaders.c | ||
evergreen_blit_shaders.h | ||
evergreen_cs.c | ||
evergreen_dma.c | ||
evergreen_hdmi.c | ||
evergreen_reg.h | ||
evergreen_smc.h | ||
evergreen.c | ||
evergreend.h | ||
Kconfig | ||
kv_dpm.c | ||
kv_dpm.h | ||
kv_smc.c | ||
Makefile | ||
mkregtable.c | ||
ni_dma.c | ||
ni_dpm.c | ||
ni_dpm.h | ||
ni_reg.h | ||
ni.c | ||
nid.h | ||
nislands_smc.h | ||
ObjectID.h | ||
ppsmc.h | ||
pptable.h | ||
r100_track.h | ||
r100.c | ||
r100d.h | ||
r200.c | ||
r300_reg.h | ||
r300.c | ||
r300d.h | ||
r420.c | ||
r420d.h | ||
r500_reg.h | ||
r520.c | ||
r520d.h | ||
r600_blit_shaders.c | ||
r600_blit_shaders.h | ||
r600_cs.c | ||
r600_dma.c | ||
r600_dpm.c | ||
r600_dpm.h | ||
r600_hdmi.c | ||
r600_reg.h | ||
r600.c | ||
r600d.h | ||
radeon_acpi.c | ||
radeon_acpi.h | ||
radeon_agp.c | ||
radeon_asic.c | ||
radeon_asic.h | ||
radeon_atombios.c | ||
radeon_atpx_handler.c | ||
radeon_audio.c | ||
radeon_audio.h | ||
radeon_benchmark.c | ||
radeon_bios.c | ||
radeon_clocks.c | ||
radeon_combios.c | ||
radeon_connectors.c | ||
radeon_cs.c | ||
radeon_cursor.c | ||
radeon_device.c | ||
radeon_display.c | ||
radeon_dp_auxch.c | ||
radeon_dp_mst.c | ||
radeon_drv.c | ||
radeon_drv.h | ||
radeon_encoders.c | ||
radeon_family.h | ||
radeon_fb.c | ||
radeon_fence.c | ||
radeon_gart.c | ||
radeon_gem.c | ||
radeon_i2c.c | ||
radeon_ib.c | ||
radeon_irq_kms.c | ||
radeon_kms.c | ||
radeon_legacy_crtc.c | ||
radeon_legacy_encoders.c | ||
radeon_legacy_tv.c | ||
radeon_mn.c | ||
radeon_mode.h | ||
radeon_object.c | ||
radeon_object.h | ||
radeon_pm.c | ||
radeon_prime.c | ||
radeon_reg.h | ||
radeon_ring.c | ||
radeon_sa.c | ||
radeon_semaphore.c | ||
radeon_sync.c | ||
radeon_test.c | ||
radeon_trace_points.c | ||
radeon_trace.h | ||
radeon_ttm.c | ||
radeon_ucode.c | ||
radeon_ucode.h | ||
radeon_uvd.c | ||
radeon_vce.c | ||
radeon_vm.c | ||
radeon.h | ||
rs100d.h | ||
rs400.c | ||
rs400d.h | ||
rs600.c | ||
rs600d.h | ||
rs690.c | ||
rs690d.h | ||
rs780_dpm.c | ||
rs780_dpm.h | ||
rs780d.h | ||
rv6xx_dpm.c | ||
rv6xx_dpm.h | ||
rv6xxd.h | ||
rv200d.h | ||
rv250d.h | ||
rv350d.h | ||
rv515.c | ||
rv515d.h | ||
rv730_dpm.c | ||
rv730d.h | ||
rv740_dpm.c | ||
rv740d.h | ||
rv770_dma.c | ||
rv770_dpm.c | ||
rv770_dpm.h | ||
rv770_smc.c | ||
rv770_smc.h | ||
rv770.c | ||
rv770d.h | ||
si_blit_shaders.c | ||
si_blit_shaders.h | ||
si_dma.c | ||
si_dpm.c | ||
si_dpm.h | ||
si_reg.h | ||
si_smc.c | ||
si.c | ||
sid.h | ||
sislands_smc.h | ||
smu7_discrete.h | ||
smu7_fusion.h | ||
smu7.h | ||
sumo_dpm.c | ||
sumo_dpm.h | ||
sumo_smc.c | ||
sumod.h | ||
trinity_dpm.c | ||
trinity_dpm.h | ||
trinity_smc.c | ||
trinityd.h | ||
uvd_v1_0.c | ||
uvd_v2_2.c | ||
uvd_v3_1.c | ||
uvd_v4_2.c | ||
vce_v1_0.c | ||
vce_v2_0.c |