Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7268634ybi; Wed, 5 Jun 2019 14:21:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9uaOL7sxWFaHhGi3BAMw1Go52FhWuV4RirKG9YQzyPyNNrQvbeE0U+KIxWtz9FUYl6L32 X-Received: by 2002:a63:5024:: with SMTP id e36mr1162112pgb.220.1559769669722; Wed, 05 Jun 2019 14:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559769669; cv=none; d=google.com; s=arc-20160816; b=yNNxkqmajV88zZ1o6uvnZexvWVcSSxSEW7AwVSxbN0fjVfUSA4f7jgTOeMhJKBeLoR CMa+HyFdTYQ0BVB257+c4aPJrs3UlzHwWjt3rRtFYzIeff2m2ASCzBVaEDmP5Tk6WKV3 gspl5gZHzGIgWbMwAXKDcssgxTAyW5ghv6vlEh/Pxoe4KbxA169xzMps4e6cNoPKr4JV 7/9DuPQNvBggjoXM2iY2n0ZPOQuvVoFoZQLOSeDUZ/zgIoSEOIa3FiInnaOHHW45tz0h AkuQT00vqTZ2BT3cS614+6jmZJhLXrRUvQ0ffbBXjbjGWoSaGpr/1kVlHbdmt4WS/Xbb DTsA== 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=LwuKD0qRQR6Z1DCIQ+SriQ9WugB9fmYEFY6WJV5RzOU=; b=IUkSPTtvTSgHFmdj9/Xe46TcULZ8UnjGYRvNxZ/+nu/QlS0kGVvIwiQP2uK50YuyZG bDyFRnKIdTU8oAKeTGpzjiRknNSLoEi+2N2dfUnzNBN+mRfjDrS7JdLcibfyvVW+BCAe Ny8gM4sKe9B2PwHVl+Oov9WX46O95Kw1bnR5sfcjNdu0c9TIlG+pLXPbsOpdfyQGqKuU cImQl3ZlEfczNQcxwuvW1RJw4j5P4/c9eEElB1YRNZUC0t68UDAxGz4SFO3e5mZWLHbW lqbF2rqC+Gl3gOOdnhP9BADHBNdh8rnoZDF0dVh16MrlWMNN+uNiFF14dgXuwsk150Or 7jng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=aHYJ6ng0; 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 c19si4313908pfn.0.2019.06.05.14.20.53; Wed, 05 Jun 2019 14:21:09 -0700 (PDT) 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=aHYJ6ng0; 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 S1726713AbfFEVSp (ORCPT + 99 others); Wed, 5 Jun 2019 17:18:45 -0400 Received: from mail-qk1-f179.google.com ([209.85.222.179]:45326 "EHLO mail-qk1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726561AbfFEVSn (ORCPT ); Wed, 5 Jun 2019 17:18:43 -0400 Received: by mail-qk1-f179.google.com with SMTP id s22so145632qkj.12 for ; Wed, 05 Jun 2019 14:18:42 -0700 (PDT) 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=LwuKD0qRQR6Z1DCIQ+SriQ9WugB9fmYEFY6WJV5RzOU=; b=aHYJ6ng06q78UXrqbo5EJBBIn7SflXbQr7HKsAkPaVh6IVwauI+elhLUuTxL4rsQHk ORjs1TlaeeQRlkujSAjE9Q8XZ/Jy6zoMfykruTXyjTerjV/XSCHvQHbaCpqdUGhXEpiE rKhPJhjJUj+fEhHSqb2/MhhWnoIe2Msg8A0Msdpbqc87nP0qFiZoPj9PUjvxe4MIxDhS VC7JsG+rULIw1kny1V/NpJcaSF4R1nRQOO22tH7ZG25y4QRb56uAQ44FeyyD5GsfcZYd Ju2xwQ90XH6WOfPLLpyjdwIF9iZTUnVrK/FYH7xNadvhZk0MNgJtL177Yzoe5QSDpdZF GKxg== 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=LwuKD0qRQR6Z1DCIQ+SriQ9WugB9fmYEFY6WJV5RzOU=; b=i2t0DrxnmkGDNZCxAfZx+jNSLTkcMe58q7jrefCBksKUhK/EQFxlPvcelR63gr8fQb /gdi4xo45jiJYK1oGzL6Zp2/n/lct/dY25BCfKPGSL9+IeJEiQ6pbMqJf/kQ9Z2K51ip 8VPQ8FfjfAfOKaToMtoaqKw2+lXLGoZLWJFS9UTQ/xzEHACKugqph3RG3DgHN/p/8KlO FmQHWdGxSlUCLSvTbuHEBC1otdStCuChxUEcfyMUdbBhLgx56C2pCQPHahnvAmfyGPIN vgBKreVOvMZH/LCIiM7X3jj2BXGpySBsqVT2wPiLuGhLkQ/sC2m4UEUHdX+CQ7SX8PxP DgLw== X-Gm-Message-State: APjAAAUhmqlOw3XwfA1k0MKioQg3tGr19NcScojRdN5qybq1HKtRn+hC R6byGVUcf93yeAcE/dHosGuU1A== X-Received: by 2002:a37:8007:: with SMTP id b7mr15760560qkd.102.1559769522355; Wed, 05 Jun 2019 14:18:42 -0700 (PDT) Received: from cakuba.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id c192sm5339874qkg.33.2019.06.05.14.18.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 05 Jun 2019 14:18:42 -0700 (PDT) Date: Wed, 5 Jun 2019 14:18:38 -0700 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: [oss-drivers] [PATCH][next] nfp: flower: use struct_size() helper Message-ID: <20190605141838.506a453b@cakuba.netronome.com> In-Reply-To: <20190605203827.GA22786@embeddedor> References: <20190605203827.GA22786@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, 5 Jun 2019 15:38:27 -0500, 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 nfp_tun_active_tuns { > ... > struct route_ip_info { > __be32 ipv4; > __be32 egress_port; > __be32 extra[2]; > } tun_info[]; > }; > > Make use of the struct_size() helper instead of an open-coded version > in order to avoid any potential type mistakes. > > So, replace the following form: > > sizeof(struct nfp_tun_active_tuns) + sizeof(struct route_ip_info) * count > > with: > > struct_size(payload, tun_info, count) > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva Acked-by: Jakub Kicinski Thanks!