Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp973725imu; Wed, 16 Jan 2019 10:30:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN5UVl9BojN8sAMQELLm1n6OxzEmXeY5ZjQbWdTLr4sCRHV/zD7F6lTOlDhplvo3fgbIAait X-Received: by 2002:a65:55ca:: with SMTP id k10mr10027259pgs.448.1547663427640; Wed, 16 Jan 2019 10:30:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547663427; cv=none; d=google.com; s=arc-20160816; b=lSgynmMYuHMs4gkEVr0D0uRlR9c3W+ewzn+WnRpuREaao4CAau9tD2uGYtraUWZbOs 47QR/C5aOD/irqO7kRFIx4tDB4oaeBsGnn+pV1GgRckZ5uML+KIK16TCfk8Mc3pxhRHF UsqzM/QGzg3KNCt1R2E15IufJQxfOF1qlAlTK+7/kxsgE+0ZiYkTLtJuPknYK9kx/EK9 7IO+/58OXAzoaaXZJZPSpOC7yVdnRerRX6JVBuZhTgb40n7BF3x6DLTnEpGQ7xYY8YmJ /NLdbjAtvEOVSt/gELnisbvaMC92NYhldkubFd4AI8UchoJ0jkAlVUtBhWsbsxf+RvgF /R5w== 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=0PyyZxC6udGfSPWF/daXzH4vQuE/b30z1Dtm3OdXx2Q=; b=T8LSZwcTn6MdfWpzxD3FYUISYULh/yNdfSMUuMCbZML5njuggVEAtWOKsNf0LieFdn 0NlPISE1aXlTa0nGSSJHzh34mOObz/7WOAkLFH8y1f+3gx/xHjWP6djOa/JbYXvr5oy4 wWSMT/KW81xun8fjipNHmzoWDfXz0yeCpFuejckyqe+/ntGzMs0mzNsGj+2jURL6MoSV Vdsq63aRa62MAXhmVrNYpqkWUTsc/dooJUSS0tTFEYFNjRfZ24jWxt8WHKNipNfj+4XA tnQpXhxlZ7WW4/YW3K8fKr7nx2mT/6+i9KgV7WM/+RkoHdxI8ye5sBCNaX4q57mXH3Q0 2TCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zjE68JqZ; 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 t13si6821010pgm.175.2019.01.16.10.30.08; Wed, 16 Jan 2019 10:30:27 -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=zjE68JqZ; 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 S2389166AbfAPIkt (ORCPT + 99 others); Wed, 16 Jan 2019 03:40:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:34724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729177AbfAPIkt (ORCPT ); Wed, 16 Jan 2019 03:40:49 -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 84C5320859; Wed, 16 Jan 2019 08:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547628048; bh=GXbmFQCGDHl5m5dWNXv4DarmZHUxdLCFv1bv1UxIb6g=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=zjE68JqZlcaQYtoFhxObQn0lbu/n7sxT9lIZMr3ZMbexCzF7cQ3sPKUQ14QgbU7B1 PDdz1tLaAShEKOV3nToS4WTaspegALeJBEEeQzvzKVx1aNt7ODUeOmhTu/1Lr89O6E qsTUyuFWrMTO/xoeZiUVKFBh1WcioTbTMEr5cdkk= 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: cfi: cmdset_0001: Use struct_size() in kmalloc() Date: Wed, 16 Jan 2019 09:40:40 +0100 Message-Id: <20190116084040.29707-1-bbrezillon@kernel.org> X-Mailer: git-send-email 2.17.1 X-linux-mtd-patch-notification: thanks X-linux-mtd-patch-commit: 04b4c06caf2b810f0ce4822f6611ed35326ca11a In-Reply-To: <20190108155244.GA15339@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 15:52:44 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 = kmalloc(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 = kmalloc(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