mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 21:38:32 +08: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> |
||
---|---|---|
.. | ||
aacraid | ||
aic7xxx | ||
aic94xx | ||
arcmsr | ||
arm | ||
be2iscsi | ||
bfa | ||
bnx2fc | ||
bnx2i | ||
csiostor | ||
cxgbi | ||
cxlflash | ||
device_handler | ||
dpt | ||
esas2r | ||
fcoe | ||
fnic | ||
hisi_sas | ||
ibmvscsi | ||
ibmvscsi_tgt | ||
isci | ||
libfc | ||
libsas | ||
lpfc | ||
megaraid | ||
mpt3sas | ||
mvsas | ||
osd | ||
pcmcia | ||
pm8001 | ||
qedf | ||
qedi | ||
qla2xxx | ||
qla4xxx | ||
smartpqi | ||
snic | ||
sym53c8xx_2 | ||
ufs | ||
.gitignore | ||
3w-9xxx.c | ||
3w-9xxx.h | ||
3w-sas.c | ||
3w-sas.h | ||
3w-xxxx.c | ||
3w-xxxx.h | ||
53c700_d.h_shipped | ||
53c700.c | ||
53c700.h | ||
53c700.scr | ||
a100u2w.c | ||
a100u2w.h | ||
a2091.c | ||
a2091.h | ||
a3000.c | ||
a3000.h | ||
a4000t.c | ||
advansys.c | ||
aha152x.c | ||
aha152x.h | ||
aha1542.c | ||
aha1542.h | ||
aha1740.c | ||
aha1740.h | ||
am53c974.c | ||
atari_scsi.c | ||
atp870u.c | ||
atp870u.h | ||
BusLogic.c | ||
BusLogic.h | ||
bvme6000_scsi.c | ||
ch.c | ||
constants.c | ||
dc395x.c | ||
dc395x.h | ||
dmx3191d.c | ||
dpt_i2o.c | ||
dpti.h | ||
esp_scsi.c | ||
esp_scsi.h | ||
FlashPoint.c | ||
g_NCR5380.c | ||
gdth_ioctl.h | ||
gdth_proc.c | ||
gdth_proc.h | ||
gdth.c | ||
gdth.h | ||
gvp11.c | ||
gvp11.h | ||
hosts.c | ||
hpsa_cmd.h | ||
hpsa.c | ||
hpsa.h | ||
hptiop.c | ||
hptiop.h | ||
imm.c | ||
imm.h | ||
initio.c | ||
initio.h | ||
ipr.c | ||
ipr.h | ||
ips.c | ||
ips.h | ||
iscsi_boot_sysfs.c | ||
iscsi_tcp.c | ||
iscsi_tcp.h | ||
jazz_esp.c | ||
Kconfig | ||
lasi700.c | ||
libiscsi_tcp.c | ||
libiscsi.c | ||
mac53c94.c | ||
mac53c94.h | ||
mac_esp.c | ||
mac_scsi.c | ||
Makefile | ||
megaraid.c | ||
megaraid.h | ||
mesh.c | ||
mesh.h | ||
mvme16x_scsi.c | ||
mvme147.c | ||
mvme147.h | ||
mvumi.c | ||
mvumi.h | ||
ncr53c8xx.c | ||
ncr53c8xx.h | ||
NCR5380.c | ||
NCR5380.h | ||
NCR_D700.c | ||
NCR_D700.h | ||
NCR_Q720.c | ||
NCR_Q720.h | ||
nsp32_debug.c | ||
nsp32_io.h | ||
nsp32.c | ||
nsp32.h | ||
osst_detect.h | ||
osst_options.h | ||
osst.c | ||
osst.h | ||
pmcraid.c | ||
pmcraid.h | ||
ppa.c | ||
ppa.h | ||
ps3rom.c | ||
qla1280.c | ||
qla1280.h | ||
qlogicfas408.c | ||
qlogicfas408.h | ||
qlogicfas.c | ||
qlogicpti.c | ||
qlogicpti.h | ||
raid_class.c | ||
script_asm.pl | ||
scsi_common.c | ||
scsi_debug.c | ||
scsi_debugfs.c | ||
scsi_debugfs.h | ||
scsi_devinfo.c | ||
scsi_dh.c | ||
scsi_error.c | ||
scsi_ioctl.c | ||
scsi_lib_dma.c | ||
scsi_lib.c | ||
scsi_logging.c | ||
scsi_logging.h | ||
scsi_netlink.c | ||
scsi_pm.c | ||
scsi_priv.h | ||
scsi_proc.c | ||
scsi_sas_internal.h | ||
scsi_scan.c | ||
scsi_sysctl.c | ||
scsi_sysfs.c | ||
scsi_trace.c | ||
scsi_transport_api.h | ||
scsi_transport_fc.c | ||
scsi_transport_iscsi.c | ||
scsi_transport_sas.c | ||
scsi_transport_spi.c | ||
scsi_transport_srp.c | ||
scsi_typedefs.h | ||
scsi.c | ||
scsi.h | ||
scsicam.c | ||
sd_dif.c | ||
sd_zbc.c | ||
sd.c | ||
sd.h | ||
sense_codes.h | ||
ses.c | ||
sg.c | ||
sgiwd93.c | ||
sim710.c | ||
sni_53c710.c | ||
sr_ioctl.c | ||
sr_vendor.c | ||
sr.c | ||
sr.h | ||
st_options.h | ||
st.c | ||
st.h | ||
stex.c | ||
storvsc_drv.c | ||
sun3_scsi_vme.c | ||
sun3_scsi.c | ||
sun3x_esp.c | ||
sun_esp.c | ||
virtio_scsi.c | ||
vmw_pvscsi.c | ||
vmw_pvscsi.h | ||
wd33c93.c | ||
wd33c93.h | ||
wd719x.c | ||
wd719x.h | ||
xen-scsifront.c | ||
zalon.c | ||
zorro7xx.c | ||
zorro_esp.c |