Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp972623imu; Wed, 16 Jan 2019 10:29:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN5BoIpPjYh16eBebbEeu4j4J8zTGifrkD45BiLIbf2GTEiA2PTCY1/Ua3boV+w7us7QNIRc X-Received: by 2002:a62:2082:: with SMTP id m2mr10977347pfj.163.1547663368029; Wed, 16 Jan 2019 10:29:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547663368; cv=none; d=google.com; s=arc-20160816; b=1J5dE54MEVsLJS1vEFlrLN4yxJpDbGlzyLU/Vzp52rVB7TVWqfeFINiHMMocXkmbS5 hsNPKm2eiR59TT2EgSKpvKp5R4q9SzTDhAKofkR+x26PTIGD8BatGWSIv7BsXaOr3wU0 OHoax4aZAs35rpAK8YHUtWIleZk6IdK2OBHmxerh9r7TBcdtZih3yvOWJ3gzmhMhccKD FiA4gaXb70/Dk1ZxySVh6XAzFqdbiXZH3AvRe2aL6N+pD9tnyW83mbUGW3WNoB6XenfT a5SqBaiX/igQ4FcJlYeiE5bwuuRfDRAzrTJMXGw+U1Jqcil2eDx8ouFWf50K4xtn0sso gexw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5DiLds136u9iUY/X6OjY2N2bQOsJdN85EOEomESsDgU=; b=aYrNrePcu4VHv9Lyk9HP9AD47ge4CUkVtZ8aU33s8ZpJ9wRDajdCgyfLuxbVy8TgE7 /tG0d2KHnXaMAaiHBWF1ZoO9Rj9kB/bM63OOn05b5NhRshfCcWTdRsFuCn19YzGQh51n AMmEmf5YXnrEs2EeZYZsjdqGwX0bzAcUM54KIK4vbsxwvH4GqbLQ93mVJv9wivXH5DDO SkBqsF9BM0VaJFsaqLeD67H07xvenI3tTt1eTZeag58wJyG1SExq8dfyfxp5hCLPS05W RqTi8lOlltfwvTKZEHYQkmOiFfhmu+3EpZExHbGmXqqwgfMaWrsYON4h1RQNWw0iiRaf Ko3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eobEc69y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i69si6890249pgd.71.2019.01.16.10.29.08; Wed, 16 Jan 2019 10:29:28 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=eobEc69y; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389099AbfAPIkf (ORCPT + 99 others); Wed, 16 Jan 2019 03:40:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:34564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729177AbfAPIkf (ORCPT ); Wed, 16 Jan 2019 03:40:35 -0500 Received: from localhost.localdomain (91-160-177-164.subs.proxad.net [91.160.177.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9588B2082F; Wed, 16 Jan 2019 08:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547628034; bh=REZp0kgkXDT/X19DOI1MmwqxPHPSj6ZVD1XwMxTrXbY=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=eobEc69y4hVI4vgaYory2u3hUKvNIa4EIUyDwW2vhd9X4XHP4DAJ5rEoU8LvRmzz5 K8hnaBD93qOcZeShQ4hyJwOycj5c4iREtuVMQv42M2JzGzS0fSv10iyojZPOYFV2qp ZazGR4D4BLwu2KDtHyT9PgmceDg/R2YqIVF8YpWs= From: Boris Brezillon To: "Gustavo A. R. Silva" , David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger Cc: Boris Brezillon , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: mtd: lpddr: Use struct_size() in kzalloc() Date: Wed, 16 Jan 2019 09:40:26 +0100 Message-Id: <20190116084026.29622-1-bbrezillon@kernel.org> X-Mailer: git-send-email 2.17.1 X-linux-mtd-patch-notification: thanks X-linux-mtd-patch-commit: 2037f9d8c242af5d549dd5ba32ff1ec1f49ceaad In-Reply-To: <20190108210946.GA4014@embeddedor> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Boris Brezillon On Tue, 2019-01-08 at 21:09:46 UTC, "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 = 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); > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva Applied to http://git.infradead.org/linux-mtd.git mtd/next, thanks. Boris