Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1835992imm; Mon, 3 Sep 2018 10:40:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdagT5+ZVt55cgS9pNFCEli3uGN9AIsQKaNs11RxN2uJFzJv5W6Z6k0rozE93ogs5TTkFMby X-Received: by 2002:a63:1823:: with SMTP id y35-v6mr27501089pgl.438.1535996450826; Mon, 03 Sep 2018 10:40:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535996450; cv=none; d=google.com; s=arc-20160816; b=X8igzi/SH2Y2QaapayL8A3d7/HgJ5qWnsPAaCGCW7LftjVVO8W/6RS65CbafIF3a8L ct72MmxmuPjDK2A7tRAy+a2OCWtHrYJft58cPdKv39aMyvAl4NS+C7MM8cZdFJxkNaxP CgFTe4d3rJ6HncfcWPk3ZWt8F19khEU69VMuF+ZIzlKoNCQ1Gy6nGNzdOB0+GQ3li/5v pf8CijYXeLKof7pjCvswtNrhv0y8Q2NUxUA55y8A71MGO7Czo1B0Ca3YvMbHFjWghFzv kGS/oPf2P+eHH1xdM6n3piywUllM3aljbLp0uzLgzRsaueSWbXj9pV+clNlMZ/iW20ZW M0cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=q4YEhV9KfC+NFKcokSi/AP/wBq26zCpupamdsP1QsIE=; b=VHvaJrn+znnh4SS0BHSVO/Ok0hrklte43kf+BcsSbK3A/nDwbKCMnmp1BnngE6QDGT AnIjR7Rph8tmiDILWZLoJ0xzH9e4p8UMr1R+cLPJaK/5ucHK/AdsjqQD2CACztyQRFTs UklVg7M81YKYl4If62y8YKpH/OG/QwsmHiCQMM39MC2lnbINbFxbzldKHvLL269RtWrO dpjlwcRXX6MZHbQJgA+OyXKVHBK4YemrQCB9bAfX2PrCpxk9/rgzOaoy1pcOdJqdGIZy dp+ysNX4dxhanEZTQ2+apiKF8V2HsEVWPH4Pwu4jNAEpDrjiP33uyQ2uVY2Lc91IKpRS 1zMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y63-v6si17690781pgd.435.2018.09.03.10.40.35; Mon, 03 Sep 2018 10:40:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731947AbeICWAm (ORCPT + 99 others); Mon, 3 Sep 2018 18:00:42 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49268 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728885AbeICWAl (ORCPT ); Mon, 3 Sep 2018 18:00:41 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 015D7BAE; Mon, 3 Sep 2018 17:39:29 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Gustavo A. R. Silva" , Kees Cook , Avi Fishman , Stephen Boyd Subject: [PATCH 4.18 116/123] clk: npcm7xx: fix memory allocation Date: Mon, 3 Sep 2018 18:57:40 +0200 Message-Id: <20180903165724.404195950@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165719.499675257@linuxfoundation.org> References: <20180903165719.499675257@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gustavo A. R. Silva commit 450b6b9b169382205f88858541a8b79830262ce7 upstream. One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example: struct foo { int stuff; void *entry[]; }; instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL); Instead of leaving these open-coded and prone to type mistakes, we can now use the new struct_size() helper: instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL); Notice that, currently, there is a bug during the allocation: sizeof(npcm7xx_clk_data) should be sizeof(*npcm7xx_clk_data) Fix this bug by using struct_size() in kzalloc() This issue was detected with the help of Coccinelle. Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook Reviewed-by: Avi Fishman Signed-off-by: Stephen Boyd Signed-off-by: Greg Kroah-Hartman --- drivers/clk/clk-npcm7xx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/clk/clk-npcm7xx.c +++ b/drivers/clk/clk-npcm7xx.c @@ -558,8 +558,8 @@ static void __init npcm7xx_clk_init(stru if (!clk_base) goto npcm7xx_init_error; - npcm7xx_clk_data = kzalloc(sizeof(*npcm7xx_clk_data->hws) * - NPCM7XX_NUM_CLOCKS + sizeof(npcm7xx_clk_data), GFP_KERNEL); + npcm7xx_clk_data = kzalloc(struct_size(npcm7xx_clk_data, hws, + NPCM7XX_NUM_CLOCKS), GFP_KERNEL); if (!npcm7xx_clk_data) goto npcm7xx_init_np_err;