Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1470747imj; Fri, 8 Feb 2019 01:57:34 -0800 (PST) X-Google-Smtp-Source: AHgI3IaefiOgxeOoyfPnbCqtyk6wAN0aP9ddFojuGLE+gWjxw8RKp1o7gdqz9UVM0S1XrkAYIasB X-Received: by 2002:a63:cc4e:: with SMTP id q14mr19401126pgi.291.1549619854259; Fri, 08 Feb 2019 01:57:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549619854; cv=none; d=google.com; s=arc-20160816; b=nMjqc0KPLQp+guw+p7t1Z5jZBmG0k2bME+61qkrXXIW5qOZNbqseDGuaYieqBqoMGY Lq+Nsr3BqeGhM4lOy/TO3xj1l/GvqJbAtheOL7Dm1osLNHtWxWpj67bdZhJp8jgSIUQN +s7Ym/22aSRmwhqJRiMsTfntmIrtuYniRepgQMn0IzbPO4cOAfjQgnIa6CpeDgAWZNbY yUdk3fgUWR97SnsbCWa2S+BTYvByS6xQByWMkUmvKiGaNitwy/vjesxPt6tVGJ4EQ7Ai bRaWJ2Y283HiFS15+1UUpKtrX01XSFllkBU2+NiAyPr9rfcR1E5FlBe8VTUrtpv4y9MM OhyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organisation:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QoUfSw22Qcs1Ily4MR50hYoGmW4pHXVIPgqfsUzWssw=; b=hd4lwbzWy0xJARr1N4TowICVsOULRfLSFoKCherf5Q1lVV5znHUoRjIBwweUeOPcV/ SjEYW8NiBDByj3vyf1Nu9uWVG0EXZYvzoxcTZt+iYN0EPjtT1ZqXnkn00jvRq9C7q3Bt F+Hw+v9YJgE395bVTppEBZ+OXgA+uIys92HTCj3lC0KlnBYbtnWp2m0C93OFFFcbS5fA BSjpS5BKWWhCsWSiPjnH6ItqEtpnfpJ1ompLVNF4dVmBgcrNq+F7n4sXTbfxqKRHuei9 Xaoac1oXVpl5ZAXzX7DP1Aed/Ti7LRxgefHtd14uN0lotOrEtRpyYpZl7BZFyKG7Osw8 K8FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@verge.net.au header.s=mail header.b=Psc6I4DF; 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 p12si1633961pgl.106.2019.02.08.01.57.18; Fri, 08 Feb 2019 01:57:34 -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=fail header.i=@verge.net.au header.s=mail header.b=Psc6I4DF; 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 S1727450AbfBHJ4x (ORCPT + 99 others); Fri, 8 Feb 2019 04:56:53 -0500 Received: from kirsty.vergenet.net ([202.4.237.240]:45305 "EHLO kirsty.vergenet.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbfBHJ4x (ORCPT ); Fri, 8 Feb 2019 04:56:53 -0500 Received: from reginn.horms.nl (watermunt.horms.nl [80.127.179.77]) by kirsty.vergenet.net (Postfix) with ESMTPA id 04DE325BE72; Fri, 8 Feb 2019 20:56:51 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=verge.net.au; s=mail; t=1549619811; bh=4iiox4Kt9PGuWxnqzfkvo074yaByLgoMV8mjvP/ryZg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Psc6I4DFHwwya6AqCfb33NuJXK1Mkx+rlogwf5X8mPA/FYtNE/vNcLkb4p/JjW1S1 r6awqVSDY/xs/xWAN0pzOCbL5DEDvRqqRbX0Azw0igdvddk1NF8dUYID8THpu2pn67 XITtZ7dS/5XptIIHrJCyD9Sc6yZfTzZXQ8s6aZ3k= Received: by reginn.horms.nl (Postfix, from userid 7100) id A9BDB940ABA; Fri, 8 Feb 2019 10:56:48 +0100 (CET) Date: Fri, 8 Feb 2019 10:56:48 +0100 From: Simon Horman To: "Gustavo A. R. Silva" Cc: Wensong Zhang , Julian Anastasov , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , netdev@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] ipvs: Use struct_size() helper Message-ID: <20190208095648.la4ushbjxkqgqzb6@verge.net.au> References: <20190208004456.GA15845@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190208004456.GA15845@embeddedor> Organisation: Horms Solutions BV User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 07, 2019 at 06:44:56PM -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[]; > }; > > size = sizeof(struct foo) + count * sizeof(struct boo); > 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: > > size = struct_size(instance, entry, count); > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva Acked-by: Simon Horman Pablo, could you consider applying this? > --- > net/netfilter/ipvs/ip_vs_ctl.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c > index 7d6318664eb2..bcd9112f47d9 100644 > --- a/net/netfilter/ipvs/ip_vs_ctl.c > +++ b/net/netfilter/ipvs/ip_vs_ctl.c > @@ -2734,8 +2734,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) > int size; > > get = (struct ip_vs_get_services *)arg; > - size = sizeof(*get) + > - sizeof(struct ip_vs_service_entry) * get->num_services; > + size = struct_size(get, entrytable, get->num_services); > if (*len != size) { > pr_err("length: %u != %u\n", *len, size); > ret = -EINVAL; > @@ -2776,8 +2775,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) > int size; > > get = (struct ip_vs_get_dests *)arg; > - size = sizeof(*get) + > - sizeof(struct ip_vs_dest_entry) * get->num_dests; > + size = struct_size(get, entrytable, get->num_dests); > if (*len != size) { > pr_err("length: %u != %u\n", *len, size); > ret = -EINVAL; > -- > 2.20.1 >