Skip to content

Commit

Permalink
x86/mce/dev-mcelog: Use struct_size() helper in kzalloc()
Browse files Browse the repository at this point in the history
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 <gustavoars@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20200617211734.GA9636@embeddedor
  • Loading branch information
Gustavo A. R. Silva authored and Borislav Petkov committed Jun 18, 2020
1 parent 5d7f7d1 commit 5ba7821
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arch/x86/kernel/cpu/mce/dev-mcelog.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static __init int dev_mcelog_init_device(void)
int err;

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

Expand Down

0 comments on commit 5ba7821

Please sign in to comment.