Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2112861imm; Thu, 23 Aug 2018 14:29:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbJ3UL4IM4DukK1rQHPMAnsBkurZlUbV8gqvqnKEUukUhAg2wYwailth19HnlUZj5X3LvQK X-Received: by 2002:a17:902:b201:: with SMTP id t1-v6mr1228399plr.84.1535059787435; Thu, 23 Aug 2018 14:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535059787; cv=none; d=google.com; s=arc-20160816; b=UxDbJJv6PxAyp4npSoQIms2+bW2bTiM9OiQylaHc3VLOOobazjZIaC8bCWNgZSTK+T gcSD7+YAfRsat4WbqBIlVBNPBWKw9FSaU5uNe//OwmNFS7u4Yy4PfBmRWP+GalQKK2uR 9rCysVJ8DwjyNrP3w6BlK0Dogk9EBCps3KMPqiRuR6Rghtxx/PCimW9ZOFqGb/JznRMr lrUocr7cffj827JXjgFBcdy6HH4CZafBBDu/COBUZtDsRGJy2kxHD4jmk/ZB1xZZamrs 2kcTi68s8SXMV0ES0zxwxZmurlqQOO/kgO+DP0X6hnLkqA5iVg17gFDJXCE+VjvslW/K l4rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=5HDXfiS/oCWccpAnuuH/8tLQ52SoSZKE9SR2DQyDQa4=; b=S9cFUrjHvuJS8r7sWweH2hs8oDTLPsYdXluuQ9cXdDoW1CACUAXPq+QrrnFA0BMG8E lPM2PXcgWFwIlnhUQt2caNkViQbhPssdgHfk0KKCmWPD2rsXPVmLQQ2ogpsNdc46wM9l xeSJ6DX4KssA+IA/ZNp/7hdpfguyyuQzULow0Wwl44j2Omx8djkPialCU1n7FA9NCZNQ 7bxBzhpG4Gg8qg7OcvMs4KdN3qH7Ooc8HhJDWMbKUGaxm7jUUeVQyF7tqHKnSngfKJ4O 6faFeWHXnRTmjDMhWAAYGyS1R59KwiawTlUPlnfkcfF7ZpeUsQVJYPSVrL/6OSkJ3rsx XDLg== 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 e34-v6si5464412plb.2.2018.08.23.14.29.31; Thu, 23 Aug 2018 14:29:47 -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 S1728176AbeHXA70 (ORCPT + 99 others); Thu, 23 Aug 2018 20:59:26 -0400 Received: from mail.bootlin.com ([62.4.15.54]:50640 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727829AbeHXA7Z (ORCPT ); Thu, 23 Aug 2018 20:59:25 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 1C2B920750; Thu, 23 Aug 2018 23:27:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id C18B3204AE; Thu, 23 Aug 2018 23:27:48 +0200 (CEST) Date: Thu, 23 Aug 2018 23:27:47 +0200 From: Boris Brezillon To: "Gustavo A. R. Silva" Cc: Harvey Hunt , Miquel Raynal , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Kees Cook Subject: Re: [PATCH] mtd: rawnand: jz4780: use struct_size() in devm_kzalloc() Message-ID: <20180823232747.072af43d@bbrezillon> In-Reply-To: <20180823193332.GA31602@embeddedor.com> References: <20180823193332.GA31602@embeddedor.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 23 Aug 2018 14:33:32 -0500 "Gustavo A. R. Silva" wrote: > 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); Oh, I didn't know about that one. That's nice! > > Signed-off-by: Gustavo A. R. Silva Reviewed-by: Boris Brezillon > --- > 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; >