Message ID | ZBTUB/kJYQxq/6Cj@work |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp566670wrt; Fri, 17 Mar 2023 14:22:50 -0700 (PDT) X-Google-Smtp-Source: AK7set821n0iTIC7m3lx6Pp/3r9dH9L0gi/rLGZePEF7c7wG4bq0wt4subG1wRZxHmzGh8FKsStK X-Received: by 2002:a05:6a20:7fa3:b0:cd:345e:5b10 with SMTP id d35-20020a056a207fa300b000cd345e5b10mr14043353pzj.5.1679088170330; Fri, 17 Mar 2023 14:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679088170; cv=none; d=google.com; s=arc-20160816; b=a0SelNPCfgxtscEq+PV2DuQI9X/4ImRd6jL9GTO8qomTFUqGaPW6d0zQ6EQHMQYWiP EowkFSu7EKi2N0IhltvyRv+cDTBOUvjqX98C2SJnhdEPnCmwl6W/IvlV9VWy8efqOu9x xWe5rWShTe1e7/8t1tK8WwlyeOYFSAGqIfmY1neai7Ga0n+tTsaHgp6tJfeK9FNazmuC IMOt1mCIHz/thMayLETiA/V1WdWGMvyJV96gl99+ALHLClJswO8sd1FLSl6DLRVVhLNs 1hCc5lSsfBB/svuhDIvCFIa6Uc+io1KJwizfP46ojHjVTC8zv7svMCYZK/2Peprwpepo J8VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=wWVS4S6J65BvH0oRIVS/7c6LDOVdjwmPQ6PMnkrK3cw=; b=olxEJungy2G9IY72AE/iTgc+PLFu89OUpg3PR5xzheXjUqDtJAu4otrsb+HH55qbym wrE7wAGO4Gff1ievEjJnUP0ytAbM1Ja7bNTcnVh7/hbwRZ0K+1iIbrQOssy2ANQvZI/+ aYss/zdCHUwTRcHNV6QFYKfsfL7OViUwkC4bvdVnc4eKUkBLp3jslhuQi8hpFkhDIQOr 5bSv99m4z7PpHwDQFw+t2NAJXbz3BfRF7IMxxRBcPwXM6bKcG71CTbbHSWO1qfzBZLQT /tzsi+aMxw0tvFOlUcxpFjvMvqZnwzGfFVl2CBqJYm1JMgxudPM0/De2c0RDanrTNerV Zt3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BaWU4SPz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k29-20020a634b5d000000b004fa7222723bsi3372701pgl.510.2023.03.17.14.22.35; Fri, 17 Mar 2023 14:22:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BaWU4SPz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S230330AbjCQU4S (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Fri, 17 Mar 2023 16:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230310AbjCQU4P (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 17 Mar 2023 16:56:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 321575F6DD; Fri, 17 Mar 2023 13:56:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CB22DB825DA; Fri, 17 Mar 2023 20:56:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AE28C4339B; Fri, 17 Mar 2023 20:56:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679086570; bh=VzXlHxYNFbUcVstTyt9EJfj+teDRoE31sK1fPAn46Oc=; h=Date:From:To:Cc:Subject:From; b=BaWU4SPzIsEjzmEUwROAS+A0XupSs9pAyKe6SsluWorDLlQLQ48c/R4PXMIjUoedc l6OqnAFh9uO30POohnzH1oJgyTxZ+f/Hqmxf7TTBIbB1INTdvPH5ykgGPIRQUFM0M6 /BPC2XuqpbKgsrSyVHiKQpPrFv3l4mhFidDd7VyrpyK86bvhFkoftJsZVJu/vVEDIT tBeZaCGmCb+uokVSbHxAJB1Is5v9mVVkDLuAUoezD8pLhBuHxs1nvpGNQQQAo5xLHq 4Y6JbrC9reKmg13EYFaXLK/HYGfy8PdYc4yuwIfSXuhppR2Sv38Y6n2qwZ7nNYnT4I r5R2eub3YFFyA== Date: Fri, 17 Mar 2023 14:56:39 -0600 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Felix Fietkau <nbd@nbd.name>, Lorenzo Bianconi <lorenzo@kernel.org>, Ryder Lee <ryder.lee@mediatek.com>, Shayne Chen <shayne.chen@mediatek.com>, Sean Wang <sean.wang@mediatek.com>, Kalle Valo <kvalo@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Matthias Brugger <matthias.bgg@gmail.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH][next] wifi: mt76: mt7921: Replace fake flex-arrays with flexible-array members Message-ID: <ZBTUB/kJYQxq/6Cj@work> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760651557003115724?= X-GMAIL-MSGID: =?utf-8?q?1760651557003115724?= |
Series |
[next] wifi: mt76: mt7921: Replace fake flex-arrays with flexible-array members
|
|
Commit Message
Gustavo A. R. Silva
March 17, 2023, 8:56 p.m. UTC
Zero-length arrays as fake flexible arrays are deprecated and we are
moving towards adopting C99 flexible-array members instead.
Address the following warnings found with GCC-13 and
-fstrict-flex-arrays=3 enabled:
drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:266:25: warning: array subscript 0 is outside array bounds of ‘struct mt7921_asar_dyn_limit_v2[0]’ [-Warray-bounds=]
drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:263:25: warning: array subscript 0 is outside array bounds of ‘struct mt7921_asar_dyn_limit[0]’ [-Warray-bounds=]
drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:223:28: warning: array subscript <unknown> is outside array bounds of ‘struct mt7921_asar_geo_limit_v2[0]’ [-Warray-bounds=]
drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:220:28: warning: array subscript <unknown> is outside array bounds of ‘struct mt7921_asar_geo_limit[0]’ [-Warray-bounds=]
drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:334:37: warning: array subscript i is outside array bounds of ‘u8[0]’ {aka ‘unsigned char[]’} [-Warray-bounds=]
Notice that the DECLARE_FLEX_ARRAY() helper allows for flexible-array
members in unions.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
routines on memcpy() and help us make progress towards globally
enabling -fstrict-flex-arrays=3 [1].
Link: https://github.com/KSPP/linux/issues/21
Link: https://github.com/KSPP/linux/issues/272
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
Comments
On Fri, Mar 17, 2023 at 02:56:39PM -0600, Gustavo A. R. Silva wrote: > Zero-length arrays as fake flexible arrays are deprecated and we are > moving towards adopting C99 flexible-array members instead. > > Address the following warnings found with GCC-13 and > -fstrict-flex-arrays=3 enabled: > drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:266:25: warning: array subscript 0 is outside array bounds of ‘struct mt7921_asar_dyn_limit_v2[0]’ [-Warray-bounds=] > drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:263:25: warning: array subscript 0 is outside array bounds of ‘struct mt7921_asar_dyn_limit[0]’ [-Warray-bounds=] > drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:223:28: warning: array subscript <unknown> is outside array bounds of ‘struct mt7921_asar_geo_limit_v2[0]’ [-Warray-bounds=] > drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:220:28: warning: array subscript <unknown> is outside array bounds of ‘struct mt7921_asar_geo_limit[0]’ [-Warray-bounds=] > drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.c:334:37: warning: array subscript i is outside array bounds of ‘u8[0]’ {aka ‘unsigned char[]’} [-Warray-bounds=] > > Notice that the DECLARE_FLEX_ARRAY() helper allows for flexible-array > members in unions. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE > routines on memcpy() and help us make progress towards globally > enabling -fstrict-flex-arrays=3 [1]. > > Link: https://github.com/KSPP/linux/issues/21 > Link: https://github.com/KSPP/linux/issues/272 > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h b/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h > index 35268b0890ad..6f2c4a572572 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h ... > @@ -69,7 +69,7 @@ struct mt7921_asar_geo_v2 { > u8 version; > u8 rsvd; > u8 nr_tbl; > - struct mt7921_asar_geo_limit_v2 tbl[0]; > + DECLARE_FLEX_ARRAY(struct mt7921_asar_geo_limit_v2, tbl); > } __packed; > > struct mt7921_asar_cl { > @@ -85,7 +85,7 @@ struct mt7921_asar_fg { > u8 rsvd; > u8 nr_flag; > u8 rsvd1; > - u8 flag[0]; > + u8 flag[]; I am curious to know why DECLARE_FLEX_ARRAY isn't used here. > } __packed; > > struct mt7921_acpi_sar { > -- > 2.34.1 >
On Mon, Mar 20, 2023 at 03:56:54PM +0100, Simon Horman wrote: > > struct mt7921_asar_cl { > > @@ -85,7 +85,7 @@ struct mt7921_asar_fg { > > u8 rsvd; > > u8 nr_flag; > > u8 rsvd1; > > - u8 flag[0]; > > + u8 flag[]; > > I am curious to know why DECLARE_FLEX_ARRAY isn't used here. In contrast to the other structs, there is no object of type struct mt7921_asar_fg declared in a union: 91 struct mt7921_acpi_sar { 92 u8 ver; 93 union { 94 struct mt7921_asar_dyn *dyn; 95 struct mt7921_asar_dyn_v2 *dyn_v2; 96 }; 97 union { 98 struct mt7921_asar_geo *geo; 99 struct mt7921_asar_geo_v2 *geo_v2; 100 }; 101 struct mt7921_asar_cl *countrylist; 102 struct mt7921_asar_fg *fg; 103 }; The DECLARE_FLEX_ARRAY() helper was created to declare flex-array members in unions or alone in structs[1]. -- Gustavo [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
On Mon, Mar 20, 2023 at 01:26:49PM -0600, Gustavo A. R. Silva wrote: > On Mon, Mar 20, 2023 at 03:56:54PM +0100, Simon Horman wrote: > > > struct mt7921_asar_cl { > > > @@ -85,7 +85,7 @@ struct mt7921_asar_fg { > > > u8 rsvd; > > > u8 nr_flag; > > > u8 rsvd1; > > > - u8 flag[0]; > > > + u8 flag[]; > > > > I am curious to know why DECLARE_FLEX_ARRAY isn't used here. > > In contrast to the other structs, there is no object of type struct > mt7921_asar_fg declared in a union: > > 91 struct mt7921_acpi_sar { > 92 u8 ver; > 93 union { > 94 struct mt7921_asar_dyn *dyn; > 95 struct mt7921_asar_dyn_v2 *dyn_v2; > 96 }; > 97 union { > 98 struct mt7921_asar_geo *geo; > 99 struct mt7921_asar_geo_v2 *geo_v2; > 100 }; > 101 struct mt7921_asar_cl *countrylist; > 102 struct mt7921_asar_fg *fg; > 103 }; > > The DECLARE_FLEX_ARRAY() helper was created to declare flex-array members > in unions or alone in structs[1]. Thanks for the clarification, much appreciated. FWIIW, with this information I'm happy with this patch. Reviewed-by: Simon Horman <simon.horman@corigine.com>
Hi all, Friendly ping: who can take this, please? 😄 Thanks
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h b/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h index 35268b0890ad..6f2c4a572572 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h @@ -24,7 +24,7 @@ struct mt7921_asar_dyn { u8 names[4]; u8 enable; u8 nr_tbl; - struct mt7921_asar_dyn_limit tbl[0]; + DECLARE_FLEX_ARRAY(struct mt7921_asar_dyn_limit, tbl); } __packed; struct mt7921_asar_dyn_limit_v2 { @@ -37,7 +37,7 @@ struct mt7921_asar_dyn_v2 { u8 enable; u8 rsvd; u8 nr_tbl; - struct mt7921_asar_dyn_limit_v2 tbl[0]; + DECLARE_FLEX_ARRAY(struct mt7921_asar_dyn_limit_v2, tbl); } __packed; struct mt7921_asar_geo_band { @@ -55,7 +55,7 @@ struct mt7921_asar_geo { u8 names[4]; u8 version; u8 nr_tbl; - struct mt7921_asar_geo_limit tbl[0]; + DECLARE_FLEX_ARRAY(struct mt7921_asar_geo_limit, tbl); } __packed; struct mt7921_asar_geo_limit_v2 { @@ -69,7 +69,7 @@ struct mt7921_asar_geo_v2 { u8 version; u8 rsvd; u8 nr_tbl; - struct mt7921_asar_geo_limit_v2 tbl[0]; + DECLARE_FLEX_ARRAY(struct mt7921_asar_geo_limit_v2, tbl); } __packed; struct mt7921_asar_cl { @@ -85,7 +85,7 @@ struct mt7921_asar_fg { u8 rsvd; u8 nr_flag; u8 rsvd1; - u8 flag[0]; + u8 flag[]; } __packed; struct mt7921_acpi_sar {