Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3187054imj; Mon, 11 Feb 2019 15:45:49 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib05JJMO7XgFl57lwhAD01eghiFzYmeDvYwCQLqwNzv2k7RbZO3H1iBvc72fIdwpo1D38Ae X-Received: by 2002:a17:902:8686:: with SMTP id g6mr859354plo.149.1549928749720; Mon, 11 Feb 2019 15:45:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549928749; cv=none; d=google.com; s=arc-20160816; b=GJEp7YkyUeQCYzHYZ0aVpRIzEq8S728wlPWNx7hdmDc3kcxN7DwIL1CtAtkN46fTWa RGrsIXFPmfFlpKDp29o8lAHmnH7P82SEc6OCWNqGCWf23RQLKbkztGWX4bqNec9jaJKY OICUjVER+A3sq9YGE1rpyOecmK2NkrDp99vlVHEl4a6dsmd3doPM3PcdbUYrjHj9VBTS Zx0uIoUkdgrgn1XaM1XMY08SgcKvYJMGEFm31WhvbHTjXFFr/YiviloIbTsdlhVZxRXM uQa9f36e7x1nk6eo2kz3200YnYjble84xdfGfUti6m/WV3pxyL8fOrJw3AHUiR/ufZ7x +uMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=oSERr/LLATBUB5+xoOpcCw7i1JJLurjH0vkyXJPtTUM=; b=WqTejT+jOPqgUaCRIlYqa8sX1jDq6MzbYz18fMzinJorxojemMR81hWbRTnptiiv1R XypD3fV4T1olk2azq1p5QTlvdzJbT3HyrcJxUKHLi9Seuo6g77JnghtAyYXIdxjGCVLu kYlAzuuPWYOxdgvBusXfP8Hi3QPTyQSzgWjaLbUjY96DiYGIDpxbwrM0S7CAVzzc6ZLS y7qOFRQyKAjQaYOUL55Z6YvLqv7w1VFJK47y+NudGVmTifrHs1EhN7di+DDOLAapQ9q5 GTwE+wAwT0l0hcrGIg5zZCfKaISkpkegYAikFBVhu4trQjaCrpfZwlLcVfgkNEUBDmyo mUzA== 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 s27si10668073pgm.501.2019.02.11.15.45.33; Mon, 11 Feb 2019 15:45:49 -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; 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 S1727330AbfBKXpZ (ORCPT + 99 others); Mon, 11 Feb 2019 18:45:25 -0500 Received: from mail.us.es ([193.147.175.20]:52790 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727125AbfBKXpY (ORCPT ); Mon, 11 Feb 2019 18:45:24 -0500 Received: from antivirus1-rhel7.int (unknown [192.168.2.11]) by mail.us.es (Postfix) with ESMTP id DF2C47FC21 for ; Tue, 12 Feb 2019 00:45:22 +0100 (CET) Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id D0E4BDA874 for ; Tue, 12 Feb 2019 00:45:22 +0100 (CET) Received: by antivirus1-rhel7.int (Postfix, from userid 99) id C5CC5DA85E; Tue, 12 Feb 2019 00:45:22 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on antivirus1-rhel7.int X-Spam-Level: X-Spam-Status: No, score=-108.2 required=7.5 tests=ALL_TRUSTED,BAYES_50, SMTPAUTH_US2,USER_IN_WHITELIST autolearn=disabled version=3.4.1 Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id BAECDDA7FC; Tue, 12 Feb 2019 00:45:20 +0100 (CET) Received: from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int (F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); Tue, 12 Feb 2019 00:45:20 +0100 (CET) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int) Received: from us.es (sys.soleta.eu [212.170.55.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: 1984lsi) by entrada.int (Postfix) with ESMTPSA id 98A0B4265A2F; Tue, 12 Feb 2019 00:45:20 +0100 (CET) Date: Tue, 12 Feb 2019 00:45:20 +0100 X-SMTPAUTHUS: auth mail.us.es From: Pablo Neira Ayuso To: "Gustavo A. R. Silva" Cc: Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] netfilter: xt_recent: Use struct_size() in kvzalloc() Message-ID: <20190211234520.xjlpm4kqm5h6wvnr@salvia> References: <20190208005608.GA16399@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190208005608.GA16399@embeddedor> User-Agent: NeoMutt/20170113 (1.7.2) X-Virus-Scanned: ClamAV using ClamSMTP 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:56:08PM -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: > > size = struct_size(instance, entry, count); > instance = alloc(size, GFP_KERNEL) > > Notice that, in this case, variable sz is not necessary, hence it is > removed. > > This code was detected with the help of Coccinelle. Applied, thanks.