Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6559561yba; Wed, 1 May 2019 15:02:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkD+po9f22EKjr/BQVn6jrC5S4d15wUoEcN4IMIX9IF/u+KGvKIbmNr9bJ3EmFhRWCxiV9 X-Received: by 2002:a17:902:7207:: with SMTP id ba7mr24084972plb.329.1556748179014; Wed, 01 May 2019 15:02:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556748179; cv=none; d=google.com; s=arc-20160816; b=Le5PMUWfTk/J+vBWmIetSf6I6NYz/zN/l8B3pESQBtG7fSayxNHQ2RRUM5WcgxQdek xym+Ci23TuKZiRG9yBUwWRFAiBrDbSsuZBxHv83oiBy+MLwoXb2k6Vrzzb+rjaki49dR A/DiMKwut/kwWmmK4JH0Wj+sao1ReNbJjrAYhJS0uKZvHwsgOUw8ZuZKG3Wj+bDSKpR3 InUEe3TWeDXBo9G128cKzeoI05Rrd0p9AUwNz1Hjojo2D0b5CEyuLdCPcKMzo5pSd4oS 2R31PlzVqt/Xe78C342gKkWpg2Vu/u+RJwUoilj3UzGgJJGFkx5lMyZqfq8OOrGHhHbx OPWg== 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=BsDY8TZoOKTVnJ7LED3zdPS9fTb+gL0iBiN6hFW+RLU=; b=ZCqK//riHFCrBgR7gjfN/WbJAKvZlO8hZyEnMqE1eidOmXvYW22PHyLUHK3SAkfA/D YtKNDH31L+PUCkUz8XXOVrOxgtFUX5NzpIrnsyGMidQyqycWKfEEcWRMyGd+IxKaOLQG Ui4IWJsnXqUaqJKvLDgf8QnCEFRn8NSrdIEyxgixB8+g7M7gkTNafCAtAsGwuVbke34L 9UVyMCBsOIIvCVRV6oSV1LJYWnDxclJz77F4QkYoLHRXw/sHbP3rs0Q7w/9w9VlFTj56 ANb/xnT975+atsjnxJih6kWKreDN0bG2zVdNmH53T141ymsFr2j7YJZKnhflXxyz9FxN YnYA== 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 d4si40632919pgc.304.2019.05.01.15.02.43; Wed, 01 May 2019 15:02:59 -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 S1726242AbfEAWBP (ORCPT + 99 others); Wed, 1 May 2019 18:01:15 -0400 Received: from gateway34.websitewelcome.com ([192.185.148.200]:25164 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbfEAWBP (ORCPT ); Wed, 1 May 2019 18:01:15 -0400 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway34.websitewelcome.com (Postfix) with ESMTP id E4AB1274D877 for ; Wed, 1 May 2019 17:01:14 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id LxHuh8r252PzOLxHuhcfIz; Wed, 01 May 2019 17:01:14 -0500 X-Authority-Reason: nr=8 Received: from [189.250.119.203] (port=58416 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1hLxHr-000EDy-Su; Wed, 01 May 2019 17:01:11 -0500 Date: Wed, 1 May 2019 17:01:08 -0500 From: "Gustavo A. R. Silva" To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] netfilter: xt_hashlimit: use struct_size() helper Message-ID: <20190501220108.GA30487@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.119.203 X-Source-L: No X-Exim-ID: 1hLxHr-000EDy-Su X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.119.203]:58416 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 8 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 Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used. So, replace code of the following form: sizeof(struct xt_hashlimit_htable) + sizeof(struct hlist_head) * size with: struct_size(hinfo, hash, size) This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- net/netfilter/xt_hashlimit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c index 8d86e39d6280..a30536b17ee1 100644 --- a/net/netfilter/xt_hashlimit.c +++ b/net/netfilter/xt_hashlimit.c @@ -288,8 +288,7 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg, size = 16; } /* FIXME: don't use vmalloc() here or anywhere else -HW */ - hinfo = vmalloc(sizeof(struct xt_hashlimit_htable) + - sizeof(struct hlist_head) * size); + hinfo = vmalloc(struct_size(hinfo, hash, size)); if (hinfo == NULL) return -ENOMEM; *out_hinfo = hinfo; -- 2.21.0