From: Gustavo A. R. Silva Date: Wed, 17 Jun 2020 21:17:34 +0000 (-0500) Subject: x86/mce/dev-mcelog: Use struct_size() helper in kzalloc() X-Git-Tag: v5.9-rc1~186^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5ba7821bcf7d82e35582fce8fe65cd160a6954b4;p=thirdparty%2Flinux.git 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 Signed-off-by: Borislav Petkov Acked-by: Tony Luck Link: https://lkml.kernel.org/r/20200617211734.GA9636@embeddedor --- diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c index 43c466020ed5b..03e51053592ac 100644 --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c @@ -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;