Commit 5ba7821b authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Borislav Petkov

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: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Acked-by: default avatarTony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20200617211734.GA9636@embeddedor
parent 5d7f7d1d
...@@ -345,7 +345,7 @@ static __init int dev_mcelog_init_device(void) ...@@ -345,7 +345,7 @@ static __init int dev_mcelog_init_device(void)
int err; int err;
mce_log_len = max(MCE_LOG_MIN_LEN, num_online_cpus()); 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) if (!mcelog)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment