Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7233572ybi; Wed, 5 Jun 2019 13:39:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzYA3ZYukyedeFwoWRpKUIJpmY1qPV5Bq/GJrv8FbjwIQccyS2XwGEqaEw5eeebCpCL0r9 X-Received: by 2002:a17:902:9a4c:: with SMTP id x12mr4311010plv.298.1559767197820; Wed, 05 Jun 2019 13:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559767197; cv=none; d=google.com; s=arc-20160816; b=p1KMo3wd8ccytESoKW8F9KUY7bP0Wucz8QrX3NclLbv38PtsONhi8gixb6M/IXdV2H mPvGhXobBY35ZKyhtUfaL+6d/avEkEvtItqpsqPXy45MbGnXv5XwyQYPX7Rp/dWa9kdE eGVS2cNghprE8fgEoUuFHZ065bS5lOq/kXTFVtYoRY7/jwBubsjlIT+FuaCxSnl7brdM YYaItxV9O+TLETxPy+kwyBWVlGZYWkyXQpcgrVMdMWxbyb86yk5vi0S7AMEq5loiyeAA UtrCd8P77C1byPCZADmtiWEXIMzeh4LozAiA96MpaFPsgP4lX0+FyPAeEAWxGtXysDAM DlGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=q5vVoF2XZeJGqhCW4WV4ezQniL6yLGw9vowfWultieQ=; b=ag51xSG8IaAuUIGE4gz53BmSOWmjANT9MwmvFSQJ/31fu4lZXcB0bLKp8BcoaO9+0C CDYH1n3dxif/n4VI/3GERfTC/23G9TjhKb5Wb7QsDQj35tgEZQfc6WsSfJDvquOxKtj+ PCUodo0lDNMT8WSunLi/43C9XpY4WGdXYX/s/lp1EGFn+4QGK8ImA05fanvbM+K2UVqQ twU6Merl2Izzz6S6a61vCSQaLt0Qekhj65cFFNLo5zF8YAWowOsVrYDwe714es8hiuA/ SWmvRgq+6rlfX4ofVsCcH6yfp3u8QRlFnre2YntICjvdW/CA9wqi3A1LK+50f/Wq7Eal ZgNA== ARC-Authentication-Results: i=1; mx.google.com; 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 e36si30508324plb.180.2019.06.05.13.39.40; Wed, 05 Jun 2019 13:39:57 -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; 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 S1726597AbfFEUif (ORCPT + 99 others); Wed, 5 Jun 2019 16:38:35 -0400 Received: from gateway22.websitewelcome.com ([192.185.47.125]:17657 "EHLO gateway22.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726477AbfFEUif (ORCPT ); Wed, 5 Jun 2019 16:38:35 -0400 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 3829A1C4C4 for ; Wed, 5 Jun 2019 15:38:34 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id Ycg6hMYd9dnCeYcg6h003k; Wed, 05 Jun 2019 15:38:34 -0500 X-Authority-Reason: nr=8 Received: from [189.250.127.120] (port=34852 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1hYcg0-0040oS-L4; Wed, 05 Jun 2019 15:38:33 -0500 Date: Wed, 5 Jun 2019 15:38:27 -0500 From: "Gustavo A. R. Silva" To: Jakub Kicinski , "David S. Miller" Cc: oss-drivers@netronome.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] nfp: flower: use struct_size() helper Message-ID: <20190605203827.GA22786@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.127.120 X-Source-L: No X-Exim-ID: 1hYcg0-0040oS-L4 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.127.120]:34852 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 16 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c index 8c67505865a4..a7a80f4b722a 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c +++ b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c @@ -162,8 +162,7 @@ void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb) } pay_len = nfp_flower_cmsg_get_data_len(skb); - if (pay_len != sizeof(struct nfp_tun_active_tuns) + - sizeof(struct route_ip_info) * count) { + if (pay_len != struct_size(payload, tun_info, count)) { nfp_flower_cmsg_warn(app, "Corruption in tunnel keep-alive message.\n"); return; } -- 2.21.0