Skip to content

Commit 5ba7821

Browse files
GustavoARSilvasuryasaimadhu
authored andcommitted
x86/mce/dev-mcelog: Use struct_size() helper in kzalloc()
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Tony Luck <[email protected]> Link: https://lkml.kernel.org/r/20200617211734.GA9636@embeddedor
1 parent 5d7f7d1 commit 5ba7821

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/x86/kernel/cpu/mce/dev-mcelog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static __init int dev_mcelog_init_device(void)
345345
int err;
346346

347347
mce_log_len = max(MCE_LOG_MIN_LEN, num_online_cpus());
348-
mcelog = kzalloc(sizeof(*mcelog) + mce_log_len * sizeof(struct mce), GFP_KERNEL);
348+
mcelog = kzalloc(struct_size(mcelog, entry, mce_log_len), GFP_KERNEL);
349349
if (!mcelog)
350350
return -ENOMEM;
351351

0 commit comments

Comments
 (0)