From patchwork Wed Jun 17 21:17:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 11610601 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBE4290 for ; Wed, 17 Jun 2020 21:12:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FC012186A for ; Wed, 17 Jun 2020 21:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592428336; bh=ANf1viXNC0XSKoSbuh6tqRPGoE7n8+2mW4foAbx4gFA=; h=Date:From:To:Cc:Subject:List-ID:From; b=x2CEUprlmCT48HikAo/6O0Sp8rNp017vDXaFhXdMGbsIq40a6i4SDVzDus9MjoE3f M9Kkk1mxoaLobuiEXlpK2r2SNcFyooUNo/Cfv4lvQaUQmyV0DC0xIVJuzapgjySTws YsxguMJr3g0O5QLsAAm//DIMb12qymZNN5S/oH+k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726840AbgFQVMQ (ORCPT ); Wed, 17 Jun 2020 17:12:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:46426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726815AbgFQVMP (ORCPT ); Wed, 17 Jun 2020 17:12:15 -0400 Received: from embeddedor (unknown [189.207.59.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4F3F32168B; Wed, 17 Jun 2020 21:12:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592428334; bh=ANf1viXNC0XSKoSbuh6tqRPGoE7n8+2mW4foAbx4gFA=; h=Date:From:To:Cc:Subject:From; b=d9CIbwABuXthBo2IWu9UjCBvO9Vr3G7pb/PAJQ04UUt22K+WFzXtiE8ArWK2A8S7C agK8P1Jg2kANEKx3ek+T7JMztHCU/L10yFGt9eQ7vji9wpu68OM5UO7K5fCIOnAxYM qGRehsVrw5g/F3zYwEh4WqcYPfLUrxLCJNh9dGcc= Date: Wed, 17 Jun 2020 16:17:34 -0500 From: "Gustavo A. R. Silva" To: Tony Luck , Borislav Petkov , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Cc: x86@kernel.org, linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] x86/mce/dev-mcelog: Use struct_size() helper in kzalloc() Message-ID: <20200617211734.GA9636@embeddedor> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-edac-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org 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 Acked-by: Tony Luck --- arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c index 43c466020ed5..03e51053592a 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;