Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1246789pxb; Sun, 12 Sep 2021 12:28:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxauXedbAcp0/pvMvgL65mI9ce+hWWgENWmvjtr8yt8fWyP2TRWLpT8qOATMKx/wR5jWPpT X-Received: by 2002:a02:11c1:: with SMTP id 184mr370558jaf.70.1631474903568; Sun, 12 Sep 2021 12:28:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631474903; cv=none; d=google.com; s=arc-20160816; b=dE0dHqxhWTG4sp6l+mo1Ya4ZgUNdmYsZw+RxThzKf7+Db/J/MGvf58wqpVhCBa7BMv 6BVgHXomF6yHK3LUkYsL7JdjkboDCq1RR7oOVE94YJW/fahApmjGgIPi9/2SckrJCy68 d9IlJSSAtJY0D0eM3qexXewClrZLF6+jO2Dn5st0mBeEGLLIYdx4z/vX5c/P20eRBIPz bR8+nnm7W9ivLylnQC/xPVrlA1EePMZX4wgFtHNy1XFODgVKsCbYQ+DcR0yMhX4V6mzs Lf1KrZek6S5uaPhe6XS7UFqZb6IvRV/ukP6NYo3GjX7LEzNLm8UuVtAGrHwu6XcZQEdo JudA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=eUSuPhzx1cW5FC/CUe6hIBOpw+auW3WSw8uRLo2lp0c=; b=IkkfC1D9K3w53FLwC0P0C1yoQYVGq5+JSvbH/JNBukiwGN4EnWwY5uq8Ts6BLG0tey PCKpGzD5GLorgu45GNvtxFXbHrxSdk9UOuKVxahUi4BD7a/QojrYeqvQvVLbThO9YHCB 39WuxF+P738mE23r5qiPvgp/cjkSmjDbLU8UZY1URGLrkQ1/z/2fK64vOb4J5v6unmUj rUvsqAU64Smx8/7RJgxINx5WFV9RLWg5Q2Lv0w09X/8xuhz0bcLljrqYMowsaJiAlvCO wUuooH3n6ffp7GgY49B8lC/jElYEr9GzK9R+JbLcXu+nOz5uBuSzlBMdpI8tP+RNuSEk TodQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="j+Fckx/e"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f17si483339iow.57.2021.09.12.12.28.06; Sun, 12 Sep 2021 12:28:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="j+Fckx/e"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235928AbhILT3O (ORCPT + 99 others); Sun, 12 Sep 2021 15:29:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:53950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234625AbhILT3O (ORCPT ); Sun, 12 Sep 2021 15:29:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D5FC60F6C; Sun, 12 Sep 2021 19:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631474879; bh=vmtoFuG0plpPFF+EQhhTtgHGfdTsRfks9YatKXBlEeQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=j+Fckx/eoaFlsEVTEDbx5ul9vBoH7/iYrdmWBpOKDmeptkrcvSfHQpJa27yVzWT84 SNsC9UzDPYBzovTcZ9Oyt/mEltGokJ8RQ2mV1ayDiAiA6wCw95WUSr3cpcbyg+5vDu Yjb8mytvs3rNrrQuLTAo7PDBmZaa+uToQ4k4jFFxJwBZc2366cRl5bkaddRGdyROp9 yeSr9Kjb1escQT8pibROK3y9sPWOqbHX+Kx9z7ugl7Z1EQuNIZKR7zckLz+mPiVOpC N325kZBrI2Rx6d9jopqvmogWBSKJlaFsjQdrr4oCNi9WqKVGD8u+1GJ5EiDnOwN7oT NWcOIomD5Dyzw== Date: Sun, 12 Sep 2021 14:31:40 -0500 From: "Gustavo A. R. Silva" To: Len Baker Cc: Kalle Valo , "David S. Miller" , Jakub Kicinski , "Gustavo A. R. Silva" , Kees Cook , ath11k@lists.infradead.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ath11k: Replace one-element array with flexible-array member Message-ID: <20210912193140.GC146608@embeddedor> References: <20210904114937.6644-1-len.baker@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210904114937.6644-1-len.baker@gmx.com> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org There is already a patch for this: https://lore.kernel.org/lkml/20210823172159.GA25800@embeddedor/ which I will now add to my -next tree. Thanks -- Gustavo On Sat, Sep 04, 2021 at 01:49:37PM +0200, Len Baker wrote: > There is a regular need in the kernel to provide a way to declare having > a dynamically sized set of trailing elements in a structure. Kernel code > should always use "flexible array members"[1] for these cases. The older > style of one-element or zero-length arrays should no longer be used[2]. > > Also, refactor the code a bit to make use of the struct_size() helper in > kzalloc(). > > [1] https://en.wikipedia.org/wiki/Flexible_array_member > [2] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#zero-length-and-one-element-arrays > > Signed-off-by: Len Baker > --- > drivers/net/wireless/ath/ath11k/reg.c | 7 ++----- > drivers/net/wireless/ath/ath11k/wmi.h | 2 +- > 2 files changed, 3 insertions(+), 6 deletions(-) > > diff --git a/drivers/net/wireless/ath/ath11k/reg.c b/drivers/net/wireless/ath/ath11k/reg.c > index e1a1df169034..c83d265185f1 100644 > --- a/drivers/net/wireless/ath/ath11k/reg.c > +++ b/drivers/net/wireless/ath/ath11k/reg.c > @@ -97,7 +97,6 @@ int ath11k_reg_update_chan_list(struct ath11k *ar) > struct channel_param *ch; > enum nl80211_band band; > int num_channels = 0; > - int params_len; > int i, ret; > > bands = hw->wiphy->bands; > @@ -117,10 +116,8 @@ int ath11k_reg_update_chan_list(struct ath11k *ar) > if (WARN_ON(!num_channels)) > return -EINVAL; > > - params_len = sizeof(struct scan_chan_list_params) + > - num_channels * sizeof(struct channel_param); > - params = kzalloc(params_len, GFP_KERNEL); > - > + params = kzalloc(struct_size(params, ch_param, num_channels), > + GFP_KERNEL); > if (!params) > return -ENOMEM; > > diff --git a/drivers/net/wireless/ath/ath11k/wmi.h b/drivers/net/wireless/ath/ath11k/wmi.h > index d35c47e0b19d..d9c83726f65d 100644 > --- a/drivers/net/wireless/ath/ath11k/wmi.h > +++ b/drivers/net/wireless/ath/ath11k/wmi.h > @@ -3608,7 +3608,7 @@ struct wmi_stop_scan_cmd { > struct scan_chan_list_params { > u32 pdev_id; > u16 nallchans; > - struct channel_param ch_param[1]; > + struct channel_param ch_param[]; > }; > > struct wmi_scan_chan_list_cmd { > -- > 2.25.1 >