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=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 20C82C43387 for ; Tue, 15 Jan 2019 17:58:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E7AEF20657 for ; Tue, 15 Jan 2019 17:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388592AbfAOR6p convert rfc822-to-8bit (ORCPT ); Tue, 15 Jan 2019 12:58:45 -0500 Received: from mail.bootlin.com ([62.4.15.54]:33207 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727667AbfAOR6o (ORCPT ); Tue, 15 Jan 2019 12:58:44 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id C68C020994; Tue, 15 Jan 2019 18:58:42 +0100 (CET) Received: from xps13 (66.198.136.77.rev.sfr.net [77.136.198.66]) by mail.bootlin.com (Postfix) with ESMTPSA id 3B60F209BC; Tue, 15 Jan 2019 18:58:06 +0100 (CET) Date: Tue, 15 Jan 2019 18:58:04 +0100 From: Miquel Raynal To: "Gustavo A. R. Silva" Cc: Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mtd: rawnand: marvell: use struct_size() in devm_kzalloc() Message-ID: <20190115185804.75e482c3@xps13> In-Reply-To: <20190104182051.GA3603@embeddedor> References: <20190104182051.GA3603@embeddedor> Organization: Bootlin X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Gustavo, "Gustavo A. R. Silva" wrote on Fri, 4 Jan 2019 12:20:51 -0600: > 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 > --- Applied to nand/next. Thanks, Miquèl