Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1818652imj; Fri, 8 Feb 2019 07:51:57 -0800 (PST) X-Google-Smtp-Source: AHgI3IZquC9YswxUMkibVn43mslPyxGzRjuTkpOouUFz68sbdUDaK9yU2Gq5MCN1tTWkEigHldRu X-Received: by 2002:a63:fb15:: with SMTP id o21mr20902102pgh.211.1549641117493; Fri, 08 Feb 2019 07:51:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549641117; cv=none; d=google.com; s=arc-20160816; b=oLUNCIA1Y3ImI0+uNq+bUYA86bYZIlWEi6QVGwSsmcsHkrC1VZtT2bv+h/xX2yO1l9 EzFzGaU+1nCK96kHzK+PDLxt26dUnArMfdRcfFac4/e0cF3JNUin/h1Mj1avtiYU3uvj ZtrLZo6O/ZSIUQkMioe2z2FA/S+M7/M6v+HycvD60fyp6WD4jd0aSZ7r4XOADUpZ3BzT 3spZ7m/86fZttukog4AODmQ7Bw2hL3/K6eR/Iuw7UTqVbg4zvu8SmYYBQ71ZHS00khPn PSFLFNqM3qdsGwxmzqLf2FPYKMkR5NrnkYJ/qRBjusVD1JxhSDI0gKHLtHvQxrmMNDlP sEMw== 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=/6VVBwxJ+1rYWw3gHcPnSjlgy74CzOJh7uWUX+nBTrk=; b=B4dIcu5km1nY4gzSwo1mfVBaEOjCX6Ca4z6qpGwNLesy9rc3etVvcVKaq1lr7Lm1XE bdAqsEeyD7SRIPLWqjWIWCHYYRPrW+I5Sw96sMmnNe+rwtLr7P5vHxrQ71LToVcxDvYK aGgeCxc/i7XdPHbD+e+dDh9AijzqljA7o/mnR0LIVDW3z3Hi5ffE3xsP4BWIiQASLfNf iEN1IURuF3qA4GNq5Tjkf7Y/zd02TD/B4I2wV4DWSAyyVbsoin79Sgkce+DU9ixE9+yh ESufYFC/ztpo3ggJ7WaQIjx8AKaW+xVJsqe0zej96WKvEi4xhbrEs72EhaiglZtakWhh 0LFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=lL1GiKqC; 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 34si2367925pgt.455.2019.02.08.07.51.41; Fri, 08 Feb 2019 07:51:57 -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=lL1GiKqC; 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 S1728012AbfBHPvS (ORCPT + 99 others); Fri, 8 Feb 2019 10:51:18 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:39627 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726934AbfBHPvR (ORCPT ); Fri, 8 Feb 2019 10:51:17 -0500 Received: by mail-qt1-f195.google.com with SMTP id o6so4385294qtk.6 for ; Fri, 08 Feb 2019 07:51:16 -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=/6VVBwxJ+1rYWw3gHcPnSjlgy74CzOJh7uWUX+nBTrk=; b=lL1GiKqCXX37S4y4tz0rtE5IH9TKfu6TgI1ehvA5ekFYgMRdZnbGGatBZeNfMGDWlu mfEYLsVXUStbS3s2S8ZO/nGKR0YJXbBBt56yiZeslf3REj1q215YrW5eqE1W2Y6NmiQ6 qEglXH9h+BMeZbPUeZ7POpM1jOWb3L1aSWfYalVTN6WKRxLZ1c1FTmIt4cZ0JEr05zVi Ak2ZvX3/pI3bspJCH6NCh8Y4l9/OFA8FDPnnBXtt/PMGEr987coOl9D6GuqNNpQtZ5PG zuXzogglzFQF5UWG1pJfpw8cnCmZNRz/kONN3cJC8WkiOBvMnNy8zTV+QN1MEziro6ZL ssmw== 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=/6VVBwxJ+1rYWw3gHcPnSjlgy74CzOJh7uWUX+nBTrk=; b=OzT30QkRMmdk9j3s3dtjNeZxFRJ61rCnvJoufQcOMX2BjQIFOA20hgMCq5XQgQTct8 pMig+85f7qIAB7hm27s0OXoQdMLgXmZJfj5z8wV4UEt/NIudvVOa0xBgIP4eX1zywwK7 IOJiKrps65doL1/QV1DW/WxeRDktzk5VHd5mL77iRYvT8TI75w6YpVCNxf2NXv+Bap46 F3A6vxWBOADhgQfWA86czgMkCJzNVZi+hBdYJpknX22JFiL3RAsk2p3i1VJ2qVSIhXpa 5/E6OY2ul2PCnIOdvd8Dzdckt/qejwbvVUP3/E1ncRPYLTvL9JvgFcd9XgVAwKpGChuZ LDKQ== X-Gm-Message-State: AHQUAubecdckj1AHc8z104bM39Bvauf31aSBgRhds2FlnPKFKRHoQkQm LEQq8pnT/mowYt/7rjDueJ/EQ6i9NGI= X-Received: by 2002:a0c:806f:: with SMTP id 102mr16728304qva.89.1549641075955; Fri, 08 Feb 2019 07:51:15 -0800 (PST) Received: from cakuba.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id 8sm3956763qtr.7.2019.02.08.07.51.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Feb 2019 07:51:15 -0800 (PST) Date: Fri, 8 Feb 2019 07:51:08 -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: flower: cmsg: use struct_size() helper Message-ID: <20190208075108.68763aca@cakuba.netronome.com> In-Reply-To: <20190208034725.GA12043@embeddedor> References: <20190208034725.GA12043@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 Thu, 7 Feb 2019 21:47:25 -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[]; > }; > > size = sizeof(struct foo) + count * sizeof(void *); > instance = alloc(size, GFP_KERNEL); > > Instead of leaving these open-coded and prone to type mistakes, we can > now use the new struct_size() helper: > > instance = alloc(struct_size(instance, entry, count), GFP_KERNEL); > > Notice that, in this case, variable size is not necessary, hence > it is removed. > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva Acked-by: Jakub Kicinski