Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1591248imu; Wed, 16 Jan 2019 23:30:23 -0800 (PST) X-Google-Smtp-Source: ALg8bN4fRTTUKn/a/uLxW+FaAGUIAfXTeDDxPdELhS852sHuUBAO5k4oj3tCx/p9mbJrY2Zeahko X-Received: by 2002:a62:1289:: with SMTP id 9mr14042345pfs.102.1547710223322; Wed, 16 Jan 2019 23:30:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547710223; cv=none; d=google.com; s=arc-20160816; b=RGcDpStXpsAX/PurQNTdPM/0x6dwlfnzyuVoJBSHUmiWhZ0LQ52ZuIeamOdp0HLq3M vP4RpWfx2MOLEscbhP2fGraFln2FQxgaO+kJoOuTLI1l1n3atVgd9KmfuPdpMxTMqqEM nUIFMQYbbN5pq4QHJPDb9PSKtX0G1PSUXyoAJaFT5EEc79FaVxVMnWkh52rsd+2AmxOb i349O76G2Cx1GIKyQAzQ4xfKAuDQaoErSOEUGZVEEC9guVT0QNvYe65Kk8iQEu713uWl nfQic24DRSCJjrZes/Y7R02Zl053aS64414Fnds9NwzEzZhURIrKeqwkdTncrHnLbPpz qXOg== 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=3u+FzcLLYzNbJ/XG2kyxGD6I8FGDrPQwD8S+ZeTAn5g=; b=Jy1U5plhBthvNAtkKEhsUZBhdJ1qE80SDIUnFcNpYwwBlpI8UoIDCcWYayELv8EusF QI+3MDYT147QBHdJeY4xlvx9tkmLuiEvIa8yQvwE6VltWUOKznXsHcnek4urRhmrIc8c kcy8vVdURbFUKbhwwx/0jX4xt2TBUuyrDxmZCqwT7Vn5Mn+F+btD0rRxdaynPJMPB/H6 ITAhlVyvBidVCh1edcOGTmAWJYKBVRRpWlyc39QoFJr60gOrZqkWdRgxms9PZPM1sBPM Rna9jAOoYLRpJBEBr64RdE2FeLFNNYLn++thGz2sgqOLlCTXe18d8gVYYzcatBiZa5cE tQow== 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 q70si102213pgq.526.2019.01.16.23.30.07; Wed, 16 Jan 2019 23:30:23 -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 S2405918AbfAPRNB (ORCPT + 99 others); Wed, 16 Jan 2019 12:13:01 -0500 Received: from shards.monkeyblade.net ([23.128.96.9]:41160 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726820AbfAPRNA (ORCPT ); Wed, 16 Jan 2019 12:13:00 -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 B984814B566D6; Wed, 16 Jan 2019 09:12:59 -0800 (PST) Date: Wed, 16 Jan 2019 09:12:59 -0800 (PST) Message-Id: <20190116.091259.294872990601186476.davem@davemloft.net> To: gustavo@embeddedor.com Cc: jiri@mellanox.com, idosch@mellanox.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next] mlxsw: spectrum_nve: Use struct_size() in kzalloc() From: David Miller In-Reply-To: <20190115231429.GA25525@embeddedor> References: <20190115231429.GA25525@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]); Wed, 16 Jan 2019 09:12:59 -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: Tue, 15 Jan 2019 17:14:29 -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 issue was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva Applied.