Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp377945yba; Wed, 3 Apr 2019 10:25:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZ4mDhpdOU34vzFYvjl6+Gl7Nmh0jNgJ7ue6rS4+iYq/juM8cKDvLkFnBcYZ0IsFmPsM9b X-Received: by 2002:a17:902:1029:: with SMTP id b38mr1208220pla.204.1554312304269; Wed, 03 Apr 2019 10:25:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554312304; cv=none; d=google.com; s=arc-20160816; b=B6RJ7XXghLNmBQs5kNpe06BIZ0mZI3nyIKF8gf2XMkMa7JxUBplJOuoVjIPPPm9hK/ oLQoV2OBkOGsIlIYEjNMl2BDW4L6nUzwAZCWafg5/o0RHA5kGSnJBeIXWaVVY9CAgmjl amjv/F2+QDwdtvCQXBk+pmF1WXbOhUi132fQEf3XWd9iUmNCntHt15+JrZpb7PBHmcgo 5BSUGwu9C7HRHvAWk9fUPBNQD7U198cwTrTeJ+f3/vs61KW9ijRqmitKLJKoyr2OzbRN ZASLeZh20M30VQwwa3kTY2rxecZc/+QWVqRiLhjOEs/ofCM1XanS/8Q9gT1DMa0y53Qu eoTQ== 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=5Bhsx5feO4ASTzrzGy64ardTURGt/EzlFhS1fwZA7Dw=; b=RZhZ110EN925r41llsj/JvP50Bfg8JJFU+fF2MloOHSattTl1Hw9XoobMjTNyu/1Yv 1RfLAcVPS+UGV5H+gotbOqoZsZSPiJTlUcM+68tITB2vUd0YdU6/8xKqZDVnzXtR/aEN f+M757eCbw8+A5pjDh9aqT1LrW0fLnrwWv2RDaaDWy14cUhCN+m96BBRnqdXeTOJwCV8 zI520E+g9tUiCuF65lt7y4qsNxmAG2MhMLTV9HHZPvPU9FfslzeMBQHrQWLumcBNN3dx J7n0ksTye52FNoUm+hpdCMxw6spQxO3PcooE09qehG+vrIq7MwTp4ZMq1TkHmyYGqMC5 3sZQ== 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 b40si14497548pla.277.2019.04.03.10.24.49; Wed, 03 Apr 2019 10:25:04 -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 S1726425AbfDCRWo (ORCPT + 99 others); Wed, 3 Apr 2019 13:22:44 -0400 Received: from gateway20.websitewelcome.com ([192.185.60.19]:26933 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725959AbfDCRWo (ORCPT ); Wed, 3 Apr 2019 13:22:44 -0400 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 91EB6400D88A6 for ; Wed, 3 Apr 2019 12:02:39 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id BjHbhN2nwdnCeBjHbhCQlt; Wed, 03 Apr 2019 12:02:39 -0500 X-Authority-Reason: nr=8 Received: from [189.250.114.183] (port=42380 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1hBjHa-001mt9-Am; Wed, 03 Apr 2019 12:02:38 -0500 Date: Wed, 3 Apr 2019 12:02:36 -0500 From: "Gustavo A. R. Silva" To: Igor Mitsyanko , Avinash Patil , Sergey Matyukevich , Kalle Valo , "David S. Miller" Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] qtnfmac: replace qtnf_cmd_acl_data_size() with struct_size() Message-ID: <20190403170236.GA31637@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.114.183 X-Source-L: No X-Exim-ID: 1hBjHa-001mt9-Am X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.114.183]:42380 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 8 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 = kzalloc(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); or instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL) Based on the above, replace qtnf_cmd_acl_data_size() with the new struct_size() helper. This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- drivers/net/wireless/quantenna/qtnfmac/commands.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/quantenna/qtnfmac/commands.c b/drivers/net/wireless/quantenna/qtnfmac/commands.c index 85a2a58f4c16..534d5a4d06fb 100644 --- a/drivers/net/wireless/quantenna/qtnfmac/commands.c +++ b/drivers/net/wireless/quantenna/qtnfmac/commands.c @@ -177,14 +177,6 @@ static void qtnf_cmd_tlv_ie_set_add(struct sk_buff *cmd_skb, u8 frame_type, memcpy(tlv->ie_data, buf, len); } -static inline size_t qtnf_cmd_acl_data_size(const struct cfg80211_acl_data *acl) -{ - size_t size = sizeof(struct qlink_acl_data) + - acl->n_acl_entries * sizeof(struct qlink_mac_address); - - return size; -} - static bool qtnf_cmd_start_ap_can_fit(const struct qtnf_vif *vif, const struct cfg80211_ap_settings *s) { @@ -203,7 +195,7 @@ static bool qtnf_cmd_start_ap_can_fit(const struct qtnf_vif *vif, if (s->acl) len += sizeof(struct qlink_tlv_hdr) + - qtnf_cmd_acl_data_size(s->acl); + struct_size(s->acl, mac_addrs, s->acl->n_acl_entries); if (len > (sizeof(struct qlink_cmd) + QTNF_MAX_CMD_BUF_SIZE)) { pr_err("VIF%u.%u: can not fit AP settings: %u\n", @@ -310,7 +302,8 @@ int qtnf_cmd_send_start_ap(struct qtnf_vif *vif, } if (s->acl) { - size_t acl_size = qtnf_cmd_acl_data_size(s->acl); + size_t acl_size = struct_size(s->acl, mac_addrs, + s->acl->n_acl_entries); struct qlink_tlv_hdr *tlv = skb_put(cmd_skb, sizeof(*tlv) + acl_size); @@ -2592,7 +2585,7 @@ int qtnf_cmd_set_mac_acl(const struct qtnf_vif *vif, struct qtnf_bus *bus = vif->mac->bus; struct sk_buff *cmd_skb; struct qlink_tlv_hdr *tlv; - size_t acl_size = qtnf_cmd_acl_data_size(params); + size_t acl_size = struct_size(params, mac_addrs, params->n_acl_entries); int ret; cmd_skb = qtnf_cmd_alloc_new_cmdskb(vif->mac->macid, vif->vifid, -- 2.21.0