wifi: brcmfmac: common: Replace one-element array with flexible-array member
cover wifi: brcmfmac: common: 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 (in struct brcmf_dload_data_le) and use the struct_size() helper.
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
in struct brcmf_dload_data_le
wifi: brcmfmac: Use struct_size() in code ralated to struct
brcmf_dload_data_le
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c | 7 ++++--- .../net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le
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_dload_data_le.
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/common.c | 4 ++-- drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +2 -2
@@ -110,7 +110,7 @@ static int brcmf_c_download(struct brcmf_if *ifp, u16 flag, dload_buf->dload_type =cpu_to_le16 (DL_TYPE_CLM ); dload_buf->len =cpu_to_le32 (len); dload_buf->crc =cpu_to_le32 (0 ); - len =sizeof (*dload_buf) + len -1 ; + len =sizeof (*dload_buf) + len; err =brcmf_fil_iovar_data_set (ifp,"clmload" , dload_buf, len);
@@ -139,7 +139,7 @@ static int brcmf_c_process_clm_blob(struct brcmf_if *ifp)return 0 ; } - chunk_buf =kzalloc (sizeof (*chunk_buf) +MAX_CHUNK_LEN -1 ,GFP_KERNEL ); + chunk_buf =kzalloc (sizeof (*chunk_buf) +MAX_CHUNK_LEN ,GFP_KERNEL );if (!chunk_buf) { err = -ENOMEM ; goto done;
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +1 -1
@@ -943,7 +943,7 @@ struct brcmf_dload_data_le {__le16 dload_type;__le32 len;__le32 crc; -u8 data[1 ]; +u8 data[]; };/**
Signature · 1 line
2.34.1
PATCH 2/2 wifi: brcmfmac: Use struct_size() in code ralated to struct brcmf_dload_data_le
In reply to Gustavo A. R. SilvaPrefer 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.
In this particular case, in the open-coded version sizeof(typeof-flex-array-elements) is implicit in _count_ because the type of the flex array data is u8:
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h:941:
941 struct brcmf_dload_data_le {
942 __le16 flag; 943 __le16 dload_type; 944 __le32 len; 945 __le32 crc; 946 u8 data[];
947 };
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +4 -3
@@ -110,9 +110,9 @@ static int brcmf_c_download(struct brcmf_if *ifp, u16 flag, dload_buf->dload_type =cpu_to_le16 (DL_TYPE_CLM ); dload_buf->len =cpu_to_le32 (len); dload_buf->crc =cpu_to_le32 (0 ); - len =sizeof (*dload_buf) + len; - err =brcmf_fil_iovar_data_set (ifp,"clmload" , dload_buf, len); + err =brcmf_fil_iovar_data_set (ifp,"clmload" , dload_buf, +struct_size (dload_buf, data, len));return err; }
@@ -139,7 +139,8 @@ static int brcmf_c_process_clm_blob(struct brcmf_if *ifp)return 0 ; } - chunk_buf =kzalloc (sizeof (*chunk_buf) +MAX_CHUNK_LEN ,GFP_KERNEL ); + chunk_buf =kzalloc (struct_size (chunk_buf, data,MAX_CHUNK_LEN ), +GFP_KERNEL );if (!chunk_buf) { err = -ENOMEM ; goto done;
Signature · 1 line
2.34.1
Re: [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le
In reply to Gustavo A. R. SilvaQuoted 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_dload_data_le.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_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
Signature · 1 line
Kees Cook
Re: [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() in code ralated to struct brcmf_dload_data_le
In reply to Gustavo A. R. SilvaQuoted 17 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.
In this particular case, in the open-coded version sizeof(typeof-flex-array-elements) is implicit in _count_ because the type of the flex array data is u8:
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h:941:
941 structbrcmf_dload_data_le{942 __le16 flag; 943 __le16 dload_type; 944 __le32 len; 945 __le32 crc; 946 u8 data[];
Quoted 4 lines
947 };
Signature · 1 line
Kees Cook
Re: [PATCH 2/2][next] wifi: brcmfmac: Use struct_size() in code ralated to struct brcmf_dload_data_le
Quoted 20 lines · Kees Cook
Quoted 19 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.
In this particular case, in the open-coded version sizeof(typeof-flex-array-elements) is implicit in _count_ because the type of the flex array data is u8:
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h:941:
941 structbrcmf_dload_data_le{942 __le16 flag; 943 __le16 dload_type; 944 __le32 len; 945 __le32 crc; 946 u8 data[];947 };
Quoted 5 lines
Quoted 2 lines
Reviewed-by Kees Cook <[email protected]>
Thanks for the reviews! :)
--
Gustavo
Re: [PATCH 1/2][next] wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le
In reply to Gustavo A. R. SilvaQuoted 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_dload_data_le.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_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
Quoted 5 lines
2 patches applied to wireless-next.git, thanks.
0001650b3d89 wifi: brcmfmac: replace one-element array with flexible-array member in struct brcmf_dload_data_le 633a9b6f514c wifi: brcmfmac: Use struct_size() in code ralated to struct brcmf_dload_data_le
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/905f5b68cf93c812360d081caae5b15221db09b6.1668548907.git.gustavoars@kernel.org/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches