Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp373440imj; Fri, 8 Feb 2019 23:00:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IZt8B05qtJBDZgdOQPDIT9aXZEzKAk4+YQ5gNJCt0469YBeQl85vx2akQ37gdVtetwe4mIu X-Received: by 2002:a17:902:2aaa:: with SMTP id j39mr27612738plb.335.1549695622808; Fri, 08 Feb 2019 23:00:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549695622; cv=none; d=google.com; s=arc-20160816; b=DnPdC3Vx189wFcCsggoxuREJHlAk6z2QA3pXT82y97dD2vkGnpHh9UdktaxLfwwlsJ d5/6Vf3SpU0ovGXBbr0ZIFBRDviv40FPPDxh+pNPpmlFfofTKzkF3AiKxMtOUQr6aa/W vfZ7F5LnIUf6cMp0JR1MgU0sjPv/EZVrGOO98jYckAwG+O9QGs9gtUuUpVrExi3P3SxK OYJM2DJud3KFwNyzzOz2QmirbEQLjAUYnO+gRD73KgM7ZMcHPADASGq5t8mKiY1BYg1k gnhnkfRaxXAnpInRTVkWsTMEDDCnqiBT679ivxCM+NUMzDr2kuNSKm5dSG8fybx3PpPE 7hVA== 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=JhRGmHU1sOKjK1jV2jYvgr7fM+C+0pF6HFKvLpsK3vA=; b=DL6gAF7CU31pfafwHXNyff600goYLU6t9J79HGRGdO5ghsC+8wdO60NGLF9rLyxSDv 4vEj6CwmtTDKXWb+qzMazCRY3OYUkTb9NKYpnuoQ7uAD0W1gyghVw5lKRdzCjMc6ACap DnSctKNEJfty7VMxNf6pYpR4zQx05BwnoWmK6+Kuw7MmNaf24oO4Qx0RP9lCc+/0VsBd auIiqf9DzM8U0HQObZktCiNBU+DqIXX0OWk02c5HR9nJfo0FxDV9A5sqRYAMRH/+Uqxg q406a1nsrt9e9BQomsEUPRKi9bSgrVyIAZvtrxLY6Ypw2uLLhxTAca/DW6RWroj9bQDB Mq6w== 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 g12si4403613plo.144.2019.02.08.23.00.06; Fri, 08 Feb 2019 23:00:22 -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 S1727216AbfBIG6q (ORCPT + 99 others); Sat, 9 Feb 2019 01:58:46 -0500 Received: from shards.monkeyblade.net ([23.128.96.9]:41424 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727197AbfBIG6p (ORCPT ); Sat, 9 Feb 2019 01:58:45 -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 0D745149D93FA; Fri, 8 Feb 2019 22:58:44 -0800 (PST) Date: Fri, 08 Feb 2019 22:58:44 -0800 (PST) Message-Id: <20190208.225844.2115404241481864517.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: flower: cmsg: use struct_size() helper From: David Miller In-Reply-To: <20190208034725.GA12043@embeddedor> References: <20190208034725.GA12043@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, 08 Feb 2019 22:58:45 -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: Thu, 7 Feb 2019 21:47:25 -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; > 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: > > instance = alloc(struct_size(instance, entry, count), GFP_KERNEL); > > Notice that, in this case, variable size is not necessary, hence > it is removed. > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva Applied.