Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp1044116ima; Fri, 1 Feb 2019 15:23:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN6aEsgn4/3yBJsZ5dS1aKTJbSHKIdGAyLRJ+v3cU38hKg029zlAs9T/nP8KCerwrGBbI32u X-Received: by 2002:a62:442:: with SMTP id 63mr40639066pfe.156.1549063407782; Fri, 01 Feb 2019 15:23:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549063407; cv=none; d=google.com; s=arc-20160816; b=pPPf51Q0J4BiEgFdFZLf4Ni7zEtrIlXPDjstlfj8W21JKlAx5MNrZz7B6p63zyie3s 3lRhJ8qZ8jHqOoUJgitx3NYjzKN5/Y0iXy+ByCVnY6wfAgjmAIHB1Gz3H7IX4mAd6dnl Q0wc5p5EPkMGqKWY/qXTgcZ6sUuAfwj1W3WlXrVkg8lJQIW8qRAyYzpWg5Outv60DQLa d8eg+AmWplAYExiy6XmU3nVGnNitII8svSo0uUvn/XAbExbplu3q+RUzJFSk2IpXZG0q 8hBDoZ6fMvJ68q3MKpqz3/3MFf87xh6+cpazCaa1fz2Gbj1QLP+8ePRWvp2+X8eO5i/i MZeQ== 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 :references:in-reply-to:from:subject:cc:to:message-id:date; bh=zPMdZ7HZFtinh1G+Laj3Neg0wRaoRI7fgMpt/Gb3oG4=; b=ZDTZgevCN17+f2dczFG2MELdAKGCXxUjB7VabKd25mKNCiJQ3FlbcAxrEk0UeFRIHL 99glQLbaJvfVpFfvCCCUVKPXvG2hU7i3Fz4qxG9Hs4OWB1o8GBijSmr7KcTE6Py9Bywn xFOlN934dVhAcOIM2wj2/JctJMZEu21sFHyJpUQfD65ix+foC7zsGoAIS0Kx5JnxwrEF qirdBJdtpqgIgOyFXbbDtN6Js5mm3Ac5vM8relCCnMI88tlspITuuYPOXb5M6u3oLRZm 6ghJ/IkKQta/nTEWWISGYQLaSoYJSkZWllB/eXrx/ycseRGnYARmkNR3y+pfhHKNo9Xl gomw== 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 c17si4823639pfb.81.2019.02.01.15.23.11; Fri, 01 Feb 2019 15:23:27 -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 S1727417AbfBAXW6 (ORCPT + 99 others); Fri, 1 Feb 2019 18:22:58 -0500 Received: from shards.monkeyblade.net ([23.128.96.9]:51294 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbfBAXWz (ORCPT ); Fri, 1 Feb 2019 18:22:55 -0500 Received: from localhost (unknown [IPv6:2601:601:9f80:35cd::bf5]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id 94553144A010C; Fri, 1 Feb 2019 15:13:12 -0800 (PST) Date: Fri, 01 Feb 2019 15:13:12 -0800 (PST) Message-Id: <20190201.151312.1302495749109758446.davem@davemloft.net> To: gustavo@embeddedor.com Cc: jakub.kicinski@netronome.com, oss-drivers@netronome.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] nfp: use struct_size() in kzalloc() From: David Miller In-Reply-To: <20190131003859.GA28539@embeddedor> References: <20190131003859.GA28539@embeddedor> X-Mailer: Mew version 6.8 on Emacs 26.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Fri, 01 Feb 2019 15:13:12 -0800 (PST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Gustavo A. R. Silva" Date: Wed, 30 Jan 2019 18:38:59 -0600 > 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[]; > }; > > instance = kzalloc(sizeof(struct foo) + count * sizeof(struct boo), GFP_KERNEL); > > Instead of leaving these open-coded and prone to type mistakes, we can > now use the new struct_size() helper: > > instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL); > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva Applied.