Skip to contentSkip to conversation

wifi: brcmfmac: Replace one-element array with flexible-array member

PATCH In review Gustavo A. R. Silva 3 participants 6 messages Nov 14, 2022 – Nov 22, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover wifi: brcmfmac: Replace one-element array with flexible-array member

Hi!

This series aims to replace a one-element array with flexible-array member in drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h

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].

Gustavo A. R. Silva (2):
wifi: brcmfmac: Replace one-element array with flexible-array member
wifi: brcmfmac: Use struct_size() and array_size() in code ralated to
struct brcmf_gscan_config

 .../net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h   | 2 +-
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/pno.c      | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 wifi: brcmfmac: Replace one-element array with flexible-array member

One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct brcmf_gscan_config.

Important to mention is that doing a build before/after this patch results in no binary output differences.

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].

---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 2 +-
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/pno.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +1 -1
index f518e025d6e4..62f65dc6a3b9 100644
@@ -1049,7 +1049,7 @@ struct brcmf_gscan_config {
 	u8 count_of_channel_buckets;
 	u8 retry_threshold;
 	__le16  lost_ap_window;
-	struct brcmf_gscan_bucket_config bucket[1];
+	struct brcmf_gscan_bucket_config bucket[];
 };
 
 /**
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pno.c +1 -1
index 170c61c8136c..7c5da506637f 100644
@@ -405,7 +405,7 @@ static int brcmf_pno_config_sched_scans(struct brcmf_if *ifp)
 	if (n_buckets < 0)
 		return n_buckets;
 
-	gsz = sizeof(*gscan_cfg) + (n_buckets - 1) * sizeof(*buckets);
+	gsz = sizeof(*gscan_cfg) + n_buckets * sizeof(*buckets);
 	gscan_cfg = kzalloc(gsz, GFP_KERNEL);
 	if (!gscan_cfg) {
 		err = -ENOMEM;
Signature · 1 line
2.34.1
#4 lore raw

PATCH 2/2 wifi: brcmfmac: Use struct_size() and array_size() in code ralated to struct brcmf_gscan_config

In reply to Gustavo A. R. Silva

Prefer struct_size() over open-coded versions of idiom:

sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count

where count is the max number of items the flexible array is supposed to contain.

Also, use array_size() in call to memcpy().

---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/pno.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pno.c +3 -3
index 7c5da506637f..05f66ab13bed 100644
@@ -405,7 +405,7 @@ static int brcmf_pno_config_sched_scans(struct brcmf_if *ifp)
 	if (n_buckets < 0)
 		return n_buckets;
 
-	gsz = sizeof(*gscan_cfg) + n_buckets * sizeof(*buckets);
+	gsz = struct_size(gscan_cfg, bucket, n_buckets);
 	gscan_cfg = kzalloc(gsz, GFP_KERNEL);
 	if (!gscan_cfg) {
 		err = -ENOMEM;
@@ -434,8 +434,8 @@ static int brcmf_pno_config_sched_scans(struct brcmf_if *ifp)
 	gscan_cfg->flags = BRCMF_GSCAN_CFG_ALL_BUCKETS_IN_1ST_SCAN;
 
 	gscan_cfg->count_of_channel_buckets = n_buckets;
-	memcpy(&gscan_cfg->bucket[0], buckets,
-	       n_buckets * sizeof(*buckets));
+	memcpy(gscan_cfg->bucket, buckets,
+	       array_size(n_buckets, sizeof(*buckets)));
 
 	err = brcmf_fil_iovar_data_set(ifp, "pfn_gscan_cfg", gscan_cfg, gsz);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/2
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 7 lines · Gustavo A. R. Silva

One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct brcmf_gscan_config.

Important to mention is that doing a build before/after this patch results in no binary output differences.

Quoted 8 lines

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].

Signature · 1 line
Kees Cook
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() and array_size() in code ralated to struct brcmf_gscan_config

In reply to Gustavo A. R. Silva
Quoted 11 lines · Gustavo A. R. Silva

Prefer struct_size() over open-coded versions of idiom:

sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count

where count is the max number of items the flexible array is supposed to contain.

Also, use array_size() in call to memcpy().

Signature · 1 line
Kees Cook
#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 11 lines · Gustavo A. R. Silva

One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element array with flexible-array member in struct brcmf_gscan_config.

Important to mention is that doing a build before/after this patch results in no binary output differences.

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].

Quoted 5 lines

2 patches applied to wireless-next.git, thanks.

61b0853d0314 wifi: brcmfmac: Replace one-element array with flexible-array member f0e0897b4c7e wifi: brcmfmac: Use struct_size() and array_size() in code ralated to struct brcmf_gscan_config

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/7694550aa9a2753a73a687f61af9441c8cf52fd7.1668466470.git.gustavoars@kernel.org/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches