From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39241C43387 for ; Fri, 4 Jan 2019 18:14:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0CD51218CD for ; Fri, 4 Jan 2019 18:14:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pdbD7xni"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="jeYfp4Ho" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0CD51218CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ltZBYE3loyidGQ8LJOQ/6oor11v6ivFPJ5k9xkuGIwg=; b=pdbD7xniASKRGI R8eFS3VcHNCJ8YPDUQjnCJIZxKeSeA99fv+Sf5Vzy9MfjoAi2yztXLtsL37wrjcyuomgrs86ioPeK uUqDIbiVG7HhrUD+tu13U49h3+Sdn+IsQXW/7YlLusTqP9FqyaPCKo2RKfDCfr2UNnf+TqWKzSZZE wIA97CK+rq0KYaj0AxvjwcfXFRvPsBYPxPfgafkMyDmhCX1WrCna9SgclRowhEVxn/4TfS5f5QxWK DrBLbqp12jhG8q9m3EBSU3Bv1bJ3yLiuXZrMa0l/ynEplnyjtIkk9J0pKxD5tf/9AJ7sfGoGjZxd9 jh6oKPasA8njZ1Szg5iA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gfTzM-0005m8-8V; Fri, 04 Jan 2019 18:14:32 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gfTzH-0005lJ-Vv; Fri, 04 Jan 2019 18:14:29 +0000 Received: from bbrezillon (91-160-177-164.subs.proxad.net [91.160.177.164]) (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 9A32F218CD; Fri, 4 Jan 2019 18:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546625666; bh=yl70YXMnOZY6TSWDtyNoEOT2T8HudqSdL5M+ycZzo4k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jeYfp4Ho0q+FsMu0WoOzLu7YvbSENGHAKm+xB0VKXFzxsC9HABESIKaFqUKil4Dpu hZxGPuLZn6CmiIm/ANuld9kef8WTWlPqogSo8GgkB4iHqX1zIlCO2DE8bARPPZ91nB YYk2Uc5tBCJNAU+XM23zZUtHJfiMzRoR/HpK+j4c= Date: Fri, 4 Jan 2019 19:14:15 +0100 From: Boris Brezillon To: "Gustavo A. R. Silva" Subject: Re: [PATCH] mtd: rawnand: sunxi: Use struct_size() in devm_kzalloc() Message-ID: <20190104191415.126e4a07@bbrezillon> In-Reply-To: <20190104172637.GA28084@embeddedor> References: <20190104172637.GA28084@embeddedor> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190104_101428_040744_521B3EB9 X-CRM114-Status: GOOD ( 19.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Richard Weinberger , linux-kernel@vger.kernel.org, Marek Vasut , Chen-Yu Tsai , linux-mtd@lists.infradead.org, Miquel Raynal , Brian Norris , David Woodhouse , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Gustavo, On Fri, 4 Jan 2019 11:26:37 -0600 "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); > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva > --- > drivers/mtd/nand/raw/sunxi_nand.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi_nand.c > index e828ee50a201..f66fffe663bf 100644 > --- a/drivers/mtd/nand/raw/sunxi_nand.c > +++ b/drivers/mtd/nand/raw/sunxi_nand.c > @@ -1870,10 +1870,7 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, > return -EINVAL; > } > > - chip = devm_kzalloc(dev, > - sizeof(*chip) + > - (nsels * sizeof(struct sunxi_nand_chip_sel)), > - GFP_KERNEL); > + chip = devm_kzalloc(dev, struct_size(chip, sels, nsels), GFP_KERNEL); > if (!chip) { > dev_err(dev, "could not allocate chip\n"); > return -ENOMEM; I posted the same patch a few days back [1]. [1]http://patchwork.ozlabs.org/patch/1013855/ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel