Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2012315imm; Thu, 23 Aug 2018 12:34:58 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzOvbT77sPTdGsh24JVxS8BODzU6+uCLFAEjioarfkMxMPQGuis4A/3+LD9N7jyhJSJ/J0r X-Received: by 2002:a62:3601:: with SMTP id d1-v6mr64475266pfa.41.1535052898832; Thu, 23 Aug 2018 12:34:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535052898; cv=none; d=google.com; s=arc-20160816; b=JwG5Fs+QA+7A3j4hFV+wpUFNDG3c5i8b2Gb2PP/hscmjPvvAVG+Lfhed0npMUoGZj2 Y6vZ6U7oAIKJAr+fdy8SMBxAqWZjHe3jB2n8slVvS4twukZCw37TTI1ipHnzTr5EcFv3 J6UP2kWepYORI4tqnFNT+Q7sb/PJYuFSDLXliotFyy8Pkn71XQmczdjQaBIk6sd2g/sy 19/lwNZvdcI9xPGvYBOSstjMsu+mo9PqFqD8vZh9J3JO3kOPD1VipjapgybMtpGhbcQZ reQ2Zwt48nhawT92rhfVQkRJgX4IWkr6dlXhwZDetloctKK+HSppoOdYZCjJAYq7zwO+ MKUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=8G9lRO1J7YN9FpeMCVragHSdvbtmrmEMrgsoOlb7wcI=; b=z4Mt9PIe5NMRfkOW0n2Ar37KfLaBNg+GB1/QJ5jy2/l41wW9ww9+K68x+82Xe6X4uX RhmKRtlptsYl3ZZmcPRj/eDeRWFW5IIW4mE+wCqg1kPEqH2XalYQuGLr37hW1Jd5TMsX ZRBtww/XnDaSV10eGr3MXtEqU8Rmr/UIZe1XdWzRnk8e3IzKm4CWOfW3MXYYO7+7Ecy0 BFxwPpDY424q8APbVuqFyHcrFqQT5AxfgY2IkY2rPChboufauuccEAdp3Asru9l5rUs5 BahxPk3ZV7HK36BVTmAVzRcB0lDSfIylS9mTWukSBWK6O0Ayhl56+sJ3jKLhVds7rf64 7h9Q== 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 y4-v6si4490330pgk.583.2018.08.23.12.34.42; Thu, 23 Aug 2018 12:34:58 -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 S1726484AbeHWXEr (ORCPT + 99 others); Thu, 23 Aug 2018 19:04:47 -0400 Received: from gateway22.websitewelcome.com ([192.185.47.100]:36456 "EHLO gateway22.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726156AbeHWXEr (ORCPT ); Thu, 23 Aug 2018 19:04:47 -0400 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 485F612A0 for ; Thu, 23 Aug 2018 14:33:37 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id svMPfGitjkBj6svMPfVa0Y; Thu, 23 Aug 2018 14:33:37 -0500 X-Authority-Reason: nr=8 Received: from [189.250.40.214] (port=38272 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1fsvMO-0006II-Cv; Thu, 23 Aug 2018 14:33:36 -0500 Date: Thu, 23 Aug 2018 14:33:32 -0500 From: "Gustavo A. R. Silva" To: Harvey Hunt , Boris Brezillon , Miquel Raynal , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Kees Cook , "Gustavo A. R. Silva" Subject: [PATCH] mtd: rawnand: jz4780: use struct_size() in devm_kzalloc() Message-ID: <20180823193332.GA31602@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.40.214 X-Source-L: No X-Exim-ID: 1fsvMO-0006II-Cv X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.40.214]:38272 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 9 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 = devm_kzalloc(dev, 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 = devm_kzalloc(dev, struct_size(instance, entry, count), GFP_KERNEL); Signed-off-by: Gustavo A. R. Silva --- drivers/mtd/nand/raw/jz4780_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/jz4780_nand.c b/drivers/mtd/nand/raw/jz4780_nand.c index db4fa60..ac62395 100644 --- a/drivers/mtd/nand/raw/jz4780_nand.c +++ b/drivers/mtd/nand/raw/jz4780_nand.c @@ -352,7 +352,7 @@ static int jz4780_nand_probe(struct platform_device *pdev) return -ENODEV; } - nfc = devm_kzalloc(dev, sizeof(*nfc) + (sizeof(nfc->cs[0]) * num_banks), GFP_KERNEL); + nfc = devm_kzalloc(dev, struct_size(nfc, cs, num_banks), GFP_KERNEL); if (!nfc) return -ENOMEM; -- 2.7.4