Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6527970imu; Wed, 30 Jan 2019 16:54:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN4XKSJgRCy4ygM6HLc/jOHtFtUR+y5PTGBP5xxPKTbLD6a8Ze5Sk1j4DDBfCJn/hc3Z/TxP X-Received: by 2002:a63:8c6:: with SMTP id 189mr29741220pgi.322.1548896082095; Wed, 30 Jan 2019 16:54:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548896082; cv=none; d=google.com; s=arc-20160816; b=G9uMNRu+IgzUVi7RDPhxBFxwDqmYAPKEahGkTwXqenQPRxMCTK+wU2G4n41Q5QXkuk D2jDSRZFdtrPOGC84uckC//Cdzd6B8kPnmOV97Q5Bl/FmXT3HRG2L38pHWoTkZPBT4mf u7x5sMXjTRUIG8uXJ/ZMvB38ffsWSiDhUeJN+QFjYwXc4x4ZHWVYLP/4hFwLMOUNWgxc f8TLcU+CVrYr43o2XmQkzybsNMi6zISmxcNfXKbGzwhBVkvMnTTEHHnzoER4gR1PPgtw co9vjck2cH0YHXxTfxQqaF1cXeFsGl/fULUYxgNmK+40KNk6Xv+Lm36fg1oaht5hhxvu xxXQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=gvBL5Mbhzr7YyFMTV4GvOGKr45VTxsd6dUHm5sivECQ=; b=GxRdFbDQNeVQnLCkNbQWXduZlcEvQ3tseYEp5BalposCGroLcGwf88aSY10kh4tv7d yde8C4sG5x/hphxBs0rvIJ9yHo/hCsPhHxd8CvUJSB5xRIXLK4QfdF5NS1+nAlLv8zH5 Am8gVi+Nbb8ktWvyx2IrnFme6IXpTk70rOCDO+iRPS3NRm02yLT8E7PHs440s9CDuhhP d5SdXYGxhmpLiu3NmZBKwOGqIlAVlr/gOgUcO6JHRwwYyt9TvplvgED9uj0/bDoYpY9l FFXjaux7sfReFuSICJb6MoNaGeJS2lBx5rHqOtWd2eciHPqaWU9QImT3CLNFDKepUifk pd9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=xMFEGRCx; 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 s4si2873386plr.306.2019.01.30.16.54.26; Wed, 30 Jan 2019 16:54:42 -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=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=xMFEGRCx; 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 S1728394AbfAaAwc (ORCPT + 99 others); Wed, 30 Jan 2019 19:52:32 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:40739 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbfAaAwc (ORCPT ); Wed, 30 Jan 2019 19:52:32 -0500 Received: by mail-qk1-f193.google.com with SMTP id y16so939331qki.7 for ; Wed, 30 Jan 2019 16:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=gvBL5Mbhzr7YyFMTV4GvOGKr45VTxsd6dUHm5sivECQ=; b=xMFEGRCx0NXIjoxPP96RZP1v09KwNWv3l9i7OyqhZO1cne8yHUgkpYdaazUmlyWtl2 ctR4b+LpW03bFjlUSmqihuMI9ivFddaHkXzxtQUQ7/YpmyQnEGViT38ye3gpYSPNp59w 8c8SFC5hTRKb4uew9zTJ/dBwebjZwWnmX+mE74TUEkAf5gZptpp8TnQW0BWse93/DB4J CND8YCiOIBQwL10Mm/Zremgmlv66Gei/yQ0+Mv8H6ywmA1bVkIcoTZ7GNW25xqoUZSXT AAlAbBf+hlZg7PVhQPb01a79CMBPVY59McJolqyF4Rj2tkjwErWGg/GQnw0LVoA2BLPf Jqcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=gvBL5Mbhzr7YyFMTV4GvOGKr45VTxsd6dUHm5sivECQ=; b=BuMlZyacndZcTLUOU+uO2AzXGPl/d2lNlHCYEU9FJdxCO+9vx5peUew1GaoKvg7SuK QEMag307j2qqcbFclzQFeFmWe8QeFyg7JsAvRN0dkFR8UeQPvllD4ICmFrXOUFes1SNE aaF2hH/ROhISF7/OEZhIWPmYyoW9jQqf6iIOhRV5wE22bgEFdZq0B/db6gPMV7FkwN6j kfzXcwKo4U0uSkGQF7JTvTlIH65XBnMSvUbfZxPCyPjpxWwwBF5bt1QdP+T2lNQx6S/j VOFww2hK5OXnuv4/znYx+hT0fXyOiJLW5s2PLEm//3R9XHwTEmOx6sic0/8Unuf17pQm iC1Q== X-Gm-Message-State: AJcUukeqcyLpwokwraXcRAoKtcHrAhmNefwarZCXOYXJ6N1iJco9OQ63 xqjI+UjHV4qsRMVOOhUGktn/ew== X-Received: by 2002:a37:a80a:: with SMTP id r10mr30752930qke.2.1548895951482; Wed, 30 Jan 2019 16:52:31 -0800 (PST) Received: from cakuba.hsd1.ca.comcast.net ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id a185sm4279071qkb.1.2019.01.30.16.52.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 16:52:31 -0800 (PST) Date: Wed, 30 Jan 2019 16:52:21 -0800 From: Jakub Kicinski To: "Gustavo A. R. Silva" Cc: "David S. Miller" , oss-drivers@netronome.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] nfp: use struct_size() in kzalloc() Message-ID: <20190130165221.243d37f9@cakuba.hsd1.ca.comcast.net> In-Reply-To: <20190131003859.GA28539@embeddedor> References: <20190131003859.GA28539@embeddedor> Organization: Netronome Systems, Ltd. 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 Wed, 30 Jan 2019 18:38:59 -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; > struct boo entry[]; > }; > > instance = kzalloc(sizeof(struct foo) + count * sizeof(struct boo), 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 Acked-by: Jakub Kicinski