Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp659694ybb; Thu, 28 Mar 2019 09:37:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwCI+1O18EnG44CRGcYXN4oxKPk2+dJwpoepuxTjP1YcSJI08A2otPeeI/BSSntsItyQ1gs X-Received: by 2002:a63:114d:: with SMTP id 13mr19422420pgr.216.1553791056113; Thu, 28 Mar 2019 09:37:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553791056; cv=none; d=google.com; s=arc-20160816; b=REDEB+qJAwtRcB2jN/5ovY1cKKJatbS3qyy0RuYfW/3v5T9YLiwClyy596DCu8QKmk Ukwws4IZYLzjo9oFyBhjQcdwIJDhmSwDcWVVlWjinprXYAkQBOjJkJ1JDgDaIhyUhgpd /CK5/uE1DlgIgfe53iddxFMcUB2UvQ/jVM5Wv+HACn91sp2iErc6r5FMk5u+94L9ziaL z77OxyFuxOVqs/zkoj9w53QInWtBg+a/UEEs4tQaiOyxwdjZhao9lMhZjy+5XVAbUA2B dlRaEkkiK2LhNbPzxWKx9gofGRhQ7wf3/tPxFm3rtwhTJSWoVUR76TEqCVqYwWCiN0pD A5uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=phv3DAA6wZwdO3Wk5RUTOXTSOlLQrfSN+m55KtvbDHA=; b=dNj3B+QSTPtk1mPlSWL9mehVW61G429W+nahwf+LruOpUFiZw2Gmz201Dji24SEL2u 7hws9BbWOTYCGdDqUGwTAiKbhgOol1IHMjCEXsWBRW7t/kK0uVbjVsJhvF2vOVCjq4ws 9KafWrpjS3nduEPLihdUyydcG9Kmgb271KzmHEQShKQTj/227ewBITF2d0fWks3Q+LjS QrC8QOeeHYk9OLV7ju58EVkG9RQljib9jzGlqiYo2fFAHlUd+vnb1Ak5xf8iL/0HYQJ4 +B0cef+NCyX/jfibUogjrYl4nZwRVessnmkFqJ7lnILfwyVnzgNAba5mC5CnPKyNnrDl lLSg== 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 q11si20978300pgh.548.2019.03.28.09.37.20; Thu, 28 Mar 2019 09:37:36 -0700 (PDT) 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 S1727620AbfC1QfA (ORCPT + 99 others); Thu, 28 Mar 2019 12:35:00 -0400 Received: from gateway31.websitewelcome.com ([192.185.144.95]:19626 "EHLO gateway31.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726029AbfC1Qe7 (ORCPT ); Thu, 28 Mar 2019 12:34:59 -0400 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway31.websitewelcome.com (Postfix) with ESMTP id EFA3715FE4 for ; Thu, 28 Mar 2019 11:34:57 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 9XzVhG3sB2PzO9XzVhYRcR; Thu, 28 Mar 2019 11:34:57 -0500 X-Authority-Reason: nr=8 Received: from [189.250.117.246] (port=34150 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1h9Xyu-002VJq-IK; Thu, 28 Mar 2019 11:34:57 -0500 Date: Thu, 28 Mar 2019 11:34:19 -0500 From: "Gustavo A. R. Silva" To: Jeff Kirsher , "David S. Miller" Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] ice: Use struct_size() helper Message-ID: <20190328163419.GA5446@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.117.246 X-Source-L: No X-Exim-ID: 1h9Xyu-002VJq-IK X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.117.246]:34150 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/net/ethernet/intel/ice/ice_sched.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_sched.c b/drivers/net/ethernet/intel/ice/ice_sched.c index e0218f4c8f0b..a2dd7c74bba3 100644 --- a/drivers/net/ethernet/intel/ice/ice_sched.c +++ b/drivers/net/ethernet/intel/ice/ice_sched.c @@ -664,10 +664,10 @@ ice_sched_add_elems(struct ice_port_info *pi, struct ice_sched_node *tc_node, u16 i, num_groups_added = 0; enum ice_status status = 0; struct ice_hw *hw = pi->hw; - u16 buf_size; + size_t buf_size; u32 teid; - buf_size = sizeof(*buf) + sizeof(*buf->generic) * (num_nodes - 1); + buf_size = struct_size(buf, generic, num_nodes - 1); buf = devm_kzalloc(ice_hw_to_dev(hw), buf_size, GFP_KERNEL); if (!buf) return ICE_ERR_NO_MEMORY; -- 2.21.0