wifi: ath10k: use flexible arrays
cover wifi: ath10k: use flexible arrays
Clean up the last remaining zero-length and one-element arrays in ath10k to comply with:
https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
With these cleanups done the ath10k-check script no longer reports any issues.
---
Jeff Johnson (6):
wifi: ath10k: use flexible array in struct wmi_host_mem_chunks
wifi: ath10k: use flexible arrays for WMI start scan TLVs
wifi: ath10k: remove struct wmi_pdev_chanlist_update_event
wifi: ath10k: remove unused template structs
wifi: ath10k: use flexible array in struct wmi_tdls_peer_capabilities
wifi: ath10k: remove duplicate memset() in 10.4 TDLS peer update
drivers/net/wireless/ath/ath10k/wmi.c | 10 +++---- drivers/net/wireless/ath/ath10k/wmi.h | 55 +++++++++-------------------------- 2 files changed, 17 insertions(+), 48 deletions(-)
---
base-commit: 7133b072dfbfac8763ffb017642c9c894894c50d
change-id: 20231212-wmi_host_mem_chunks_flexarray-78264e146731
PATCH 1/6 wifi: ath10k: use flexible array in struct wmi_host_mem_chunks
Currently struct wmi_host_mem_chunks defines:
struct host_memory_chunk items[1];
Per the guidance in [1] this should be a flexible array. However there is a documented requirement:
some fw revisions require at least 1 chunk regardless of count
To satisfy this requirement, follow the guidance from [2] and wrap the array in a union which contains both the flexible array and a single instance of the underlying struct. Since the footprint of the struct is unchanged, no additional driver changes are required.
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/
--- drivers/net/wireless/ath/ath10k/wmi.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/wmi.h +4 -1
@@ -3069,7 +3069,10 @@ struct host_memory_chunk {struct wmi_host_mem_chunks {__le32 count;/* some fw revisions require at least 1 chunk regardless of count */ -struct host_memory_chunk items[1 ]; +union { +struct host_memory_chunk item; + DECLARE_FLEX_ARRAY(struct host_memory_chunk, items); + }; } __packed;struct wmi_init_cmd {
Signature · 1 line
2.42.0
Re: [PATCH 1/6] wifi: ath10k: use flexible array in struct wmi_host_mem_chunks
Quoted 12 lines · Jeff Johnson
Currently struct
wmi_host_mem_chunksdefines:struct host_memory_chunk items[1];Per the guidance in [1] this should be a flexible array. However there is a documented requirement:
some fw revisions require at least 1 chunk regardless of countTo satisfy this requirement, follow the guidance from [2] and wrap the array in a union which contains both the flexible array and a single instance of the underlying struct. Since the footprint of the struct is unchanged, no additional driver changes are required.
Quoted 6 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/Signed-off-by Jeff Johnson <[email protected]>
This looks like the right approach here.
Signature · 1 line
Kees Cook
Re: [PATCH 1/6] wifi: ath10k: use flexible array in struct wmi_host_mem_chunks
In reply to Jeff JohnsonQuoted 12 lines · Jeff Johnson
Currently struct
wmi_host_mem_chunksdefines:struct host_memory_chunk items[1];Per the guidance in [1] this should be a flexible array. However there is a documented requirement:
some fw revisions require at least 1 chunk regardless of countTo satisfy this requirement, follow the guidance from [2] and wrap the array in a union which contains both the flexible array and a single instance of the underlying struct. Since the footprint of the struct is unchanged, no additional driver changes are required.
Quoted 6 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/Signed-off-by Jeff Johnson <[email protected]>
Thanks!
--
Gustavo
Quoted 21 lines
--- drivers/net/wireless/ath/ath10k/wmi.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/net/wireless/ath/ath10k/wmi.h +4
-1@@ -3069,7 +3069,10 @@ struct host_memory_chunk {struct wmi_host_mem_chunks {__le32 count;/* some fw revisions require at least 1 chunk regardless of count */ -struct host_memory_chunk items[1 ]; +union { +struct host_memory_chunk item; + DECLARE_FLEX_ARRAY(struct host_memory_chunk, items); + }; } __packed;struct wmi_init_cmd {
Re: [PATCH 1/6] wifi: ath10k: use flexible array in struct wmi_host_mem_chunks
In reply to Jeff JohnsonQuoted 14 lines · Jeff Johnson
Currently struct
wmi_host_mem_chunksdefines:struct host_memory_chunk items[1];Per the guidance in [1] this should be a flexible array. However there is a documented requirement:
some fw revisions require at least 1 chunk regardless of countTo satisfy this requirement, follow the guidance from [2] and wrap the array in a union which contains both the flexible array and a single instance of the underlying struct. Since the footprint of the struct is unchanged, no additional driver changes are required.
No functional changes, compile tested only.
Quoted 7 lines
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/Signed-off-by Jeff Johnson <[email protected]>Reviewed-by Kees Cook <[email protected]>Reviewed-by Gustavo A. R. Silva <[email protected]>Signed-off-by Kalle Valo <[email protected]>
6 patches applied to ath-next branch of ath.git, thanks.
d2eb318f4b6b wifi: ath10k: use flexible array in struct wmi_host_mem_chunks 72ca7c4073ac wifi: ath10k: use flexible arrays for WMI start scan TLVs 26eb704a46f8 wifi: ath10k: remove struct wmi_pdev_chanlist_update_event b0c0794b05ec wifi: ath10k: remove unused template structs cb188e862c1c wifi: ath10k: use flexible array in struct wmi_tdls_peer_capabilities 6b9923f1f6d1 wifi: ath10k: remove duplicate memset() in 10.4 TDLS peer update
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/20231213-wmi_host_mem_chunks_flexarray-v1-1-92922d92fa2c@quicinc.com/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Re: [PATCH 1/6] wifi: ath10k: use flexible array in struct wmi_host_mem_chunks
Quoted 2 lines
6 patches applied to ath-next branch of ath.git, thanks.
Awesome! :)
Thanks
--
Gustavo
PATCH 2/6 wifi: ath10k: use flexible arrays for WMI start scan TLVs
In reply to Jeff JohnsonCurrently ath10k defines the following struct:
struct wmi_start_scan_tlvs {
u8 tlvs[0];
} __packed;Per the guidance in [1] this should be a flexible array. However, a direct replace to u8 tlvs[] results in the compilation error:
flexible array member in a struct with no named members
This is because C99 6.7.2.1 (16) requires that a structure containing a flexible array member must have more than one named member.
So rather than defining a separate struct wmi_start_scan_tlvs which contains the flexible tlvs[] array, just define the tlvs[] array where struct wmi_start_scan_tlvs is being used.
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/net/wireless/ath/ath10k/wmi.c | 8 ++++---- drivers/net/wireless/ath/ath10k/wmi.h | 11 ++--------- 2 files changed, 6 insertions(+), 13 deletions(-)
drivers/net/wireless/ath/ath10k/wmi.c +4 -4
@@ -6927,14 +6927,14 @@ void ath10k_wmi_put_start_scan_common(struct wmi_start_scan_common *cmn, }static void -ath10k_wmi_put_start_scan_tlvs (struct wmi_start_scan_tlvs *tlvs, +ath10k_wmi_put_start_scan_tlvs (u8 *tlvs,const struct wmi_start_scan_arg *arg) {struct wmi_ie_data *ie;struct wmi_chan_list *channels;struct wmi_ssid_list *ssids;struct wmi_bssid_list *bssids; -void *ptr = tlvs->tlvs; +void *ptr = tlvs;int i;if (arg->n_channels) {
@@ -7012,7 +7012,7 @@ ath10k_wmi_op_gen_start_scan(struct ath10k *ar, cmd = (struct wmi_start_scan_cmd *)skb->data;ath10k_wmi_put_start_scan_common (&cmd->common, arg); -ath10k_wmi_put_start_scan_tlvs (&cmd->tlvs, arg); +ath10k_wmi_put_start_scan_tlvs (cmd->tlvs, arg); cmd->burst_duration_ms =__cpu_to_le32 (0 );
@@ -7041,7 +7041,7 @@ ath10k_wmi_10x_op_gen_start_scan(struct ath10k *ar, cmd = (struct wmi_10x_start_scan_cmd *)skb->data;ath10k_wmi_put_start_scan_common (&cmd->common, arg); -ath10k_wmi_put_start_scan_tlvs (&cmd->tlvs, arg); +ath10k_wmi_put_start_scan_tlvs (cmd->tlvs, arg);ath10k_dbg (ar,ATH10K_DBG_WMI ,"wmi 10x start scan\n" );return skb;
drivers/net/wireless/ath/ath10k/wmi.h +2 -9
@@ -3218,23 +3218,16 @@ struct wmi_start_scan_common {__le32 scan_ctrl_flags; } __packed; -struct wmi_start_scan_tlvs { -/* TLV parameters. These includes channel list, ssid list, bssid list, -* extra ies. -*/ -u8 tlvs[0 ]; -} __packed; -struct wmi_start_scan_cmd {struct wmi_start_scan_common common;__le32 burst_duration_ms; -struct wmi_start_scan_tlvs tlvs; +u8 tlvs[]; } __packed;/* This is the definition from 10.X firmware branch */ struct wmi_10x_start_scan_cmd {struct wmi_start_scan_common common; -struct wmi_start_scan_tlvs tlvs; +u8 tlvs[]; } __packed;struct wmi_ssid_arg {
Signature · 1 line
2.42.0
Re: [PATCH 2/6] wifi: ath10k: use flexible arrays for WMI start scan TLVs
Quoted 16 lines · Jeff Johnson
Currently ath10k defines the following struct:
struct wmi_start_scan_tlvs { u8 tlvs[0]; } __packed;Per the guidance in [1] this should be a flexible array. However, a direct replace to u8 tlvs[] results in the compilation error:
flexible array member in a struct with no named membersThis is because C99 6.7.2.1 (16) requires that a structure containing a flexible array member must have more than one named member.
So rather than defining a separate struct
wmi_start_scan_tlvswhich contains the flexible tlvs[] array, just define the tlvs[] array where structwmi_start_scan_tlvsis being used.
Quoted 5 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
Signed-off-by Jeff Johnson <[email protected]>
Yeah, this too looks like the right approach: keeping the flex array close instead of externalized into a no-op struct.
Signature · 1 line
Kees Cook
Re: [PATCH 2/6] wifi: ath10k: use flexible arrays for WMI start scan TLVs
In reply to Jeff JohnsonQuoted 16 lines · Jeff Johnson
Currently ath10k defines the following struct:
struct wmi_start_scan_tlvs { u8 tlvs[0]; } __packed;Per the guidance in [1] this should be a flexible array. However, a direct replace to u8 tlvs[] results in the compilation error:
flexible array member in a struct with no named membersThis is because C99 6.7.2.1 (16) requires that a structure containing a flexible array member must have more than one named member.
So rather than defining a separate struct
wmi_start_scan_tlvswhich contains the flexible tlvs[] array, just define the tlvs[] array where structwmi_start_scan_tlvsis being used.
Quoted 5 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
Signed-off-by Jeff Johnson <[email protected]>
Thanks!
--
Gustavo
Quoted 75 lines
--- drivers/net/wireless/ath/ath10k/wmi.c | 8 ++++---- drivers/net/wireless/ath/ath10k/wmi.h | 11 ++--------- 2 files changed, 6 insertions(+), 13 deletions(-)drivers/net/wireless/ath/ath10k/wmi.c +4
-4@@ -6927,14 +6927,14 @@ void ath10k_wmi_put_start_scan_common(struct wmi_start_scan_common *cmn, }static void -ath10k_wmi_put_start_scan_tlvs (struct wmi_start_scan_tlvs *tlvs, +ath10k_wmi_put_start_scan_tlvs (u8 *tlvs,const struct wmi_start_scan_arg *arg) {struct wmi_ie_data *ie;struct wmi_chan_list *channels;struct wmi_ssid_list *ssids;struct wmi_bssid_list *bssids; -void *ptr = tlvs->tlvs; +void *ptr = tlvs;int i;if (arg->n_channels) {@@ -7012,7 +7012,7 @@ ath10k_wmi_op_gen_start_scan(struct ath10k *ar, cmd = (struct wmi_start_scan_cmd *)skb->data;ath10k_wmi_put_start_scan_common (&cmd->common, arg); -ath10k_wmi_put_start_scan_tlvs (&cmd->tlvs, arg); +ath10k_wmi_put_start_scan_tlvs (cmd->tlvs, arg); cmd->burst_duration_ms =__cpu_to_le32 (0 );@@ -7041,7 +7041,7 @@ ath10k_wmi_10x_op_gen_start_scan(struct ath10k *ar, cmd = (struct wmi_10x_start_scan_cmd *)skb->data;ath10k_wmi_put_start_scan_common (&cmd->common, arg); -ath10k_wmi_put_start_scan_tlvs (&cmd->tlvs, arg); +ath10k_wmi_put_start_scan_tlvs (cmd->tlvs, arg);ath10k_dbg (ar,ATH10K_DBG_WMI ,"wmi 10x start scan\n" );return skb;drivers/net/wireless/ath/ath10k/wmi.h +2
-9@@ -3218,23 +3218,16 @@ struct wmi_start_scan_common {__le32 scan_ctrl_flags; } __packed; -struct wmi_start_scan_tlvs { -/* TLV parameters. These includes channel list, ssid list, bssid list, -* extra ies. -*/ -u8 tlvs[0 ]; -} __packed; -struct wmi_start_scan_cmd {struct wmi_start_scan_common common;__le32 burst_duration_ms; -struct wmi_start_scan_tlvs tlvs; +u8 tlvs[]; } __packed;/* This is the definition from 10.X firmware branch */ struct wmi_10x_start_scan_cmd {struct wmi_start_scan_common common; -struct wmi_start_scan_tlvs tlvs; +u8 tlvs[]; } __packed;struct wmi_ssid_arg {
PATCH 3/6 wifi: ath10k: remove struct wmi_pdev_chanlist_update_event
In reply to Jeff JohnsonCurrently struct wmi_pdev_chanlist_update_event defines:
struct wmi_channel channel_list[1];
Per the guidance in [1] this should be a flexible array. However during conversion it was discovered that this struct is not used, so just remove the entire struct.
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/net/wireless/ath/ath10k/wmi.h | 7 ------- 1 file changed, 7 deletions(-)
drivers/net/wireless/ath/ath10k/wmi.h +0 -7
@@ -4256,13 +4256,6 @@ struct wmi_peer_sta_ps_state_chg_event {__le32 peer_ps_state; } __packed; -struct wmi_pdev_chanlist_update_event { -/* number of channels */ -__le32 num_chan; -/* array of channels */ -struct wmi_channel channel_list[1 ]; -} __packed; -#define WMI_MAX_DEBUG_MESG (sizeof(u32) * 32)struct wmi_debug_mesg_event {
Signature · 1 line
2.42.0
Re: [PATCH 3/6] wifi: ath10k: remove struct wmi_pdev_chanlist_update_event
Quoted 7 lines · Jeff Johnson
Currently struct
wmi_pdev_chanlist_update_eventdefines:struct wmi_channel channel_list[1];Per the guidance in [1] this should be a flexible array. However during conversion it was discovered that this struct is not used, so just remove the entire struct.
Quoted 5 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
Signed-off-by Jeff Johnson <[email protected]>
Removal of unused structs is good. :)
Signature · 1 line
Kees Cook
Re: [PATCH 3/6] wifi: ath10k: remove struct wmi_pdev_chanlist_update_event
In reply to Jeff JohnsonQuoted 6 lines · Jeff Johnson
Currently struct
wmi_pdev_chanlist_update_eventdefines:struct wmi_channel channel_list[1];Per the guidance in [1] this should be a flexible array. However during conversion it was discovered that this struct is not used, so just remove the entire struct.
Less code is always great. :)
Quoted 6 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
Signed-off-by Jeff Johnson <[email protected]>
Thanks!
--
Gustavo
Quoted 23 lines
--- drivers/net/wireless/ath/ath10k/wmi.h | 7 ------- 1 file changed, 7 deletions(-)drivers/net/wireless/ath/ath10k/wmi.h +0
-7@@ -4256,13 +4256,6 @@ struct wmi_peer_sta_ps_state_chg_event {__le32 peer_ps_state; } __packed; -struct wmi_pdev_chanlist_update_event { -/* number of channels */ -__le32 num_chan; -/* array of channels */ -struct wmi_channel channel_list[1 ]; -} __packed; -#define WMI_MAX_DEBUG_MESG (sizeof(u32) * 32)struct wmi_debug_mesg_event {
PATCH 4/6 wifi: ath10k: remove unused template structs
In reply to Jeff JohnsonCurrently both the wmi_bcn_tmpl_cmd and wmi_prb_tmpl_cmd structs define:
u8 data[1];
Per the guidance in [1] both instances of this should be flexible arrays. However during conversion it was discovered that neither of these structs are actually used, so just remove them.
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/net/wireless/ath/ath10k/wmi.h | 24 ------------------------ 1 file changed, 24 deletions(-)
drivers/net/wireless/ath/ath10k/wmi.h +0 -24
@@ -5782,30 +5782,6 @@ struct wmi_bcn_prb_info {/* app IE */ } __packed; -struct wmi_bcn_tmpl_cmd { -/* unique id identifying the VDEV, generated by the caller */ -__le32 vdev_id; -/* TIM IE offset from the beginning of the template. */ -__le32 tim_ie_offset; -/* beacon probe capabilities and IEs */ -struct wmi_bcn_prb_info bcn_prb_info; -/* beacon buffer length */ -__le32 buf_len; -/* variable length data */ -u8 data[1 ]; -} __packed; - -struct wmi_prb_tmpl_cmd { -/* unique id identifying the VDEV, generated by the caller */ -__le32 vdev_id; -/* beacon probe capabilities and IEs */ -struct wmi_bcn_prb_info bcn_prb_info; -/* beacon buffer length */ -__le32 buf_len; -/* Variable length data */ -u8 data[1 ]; -} __packed; -enum wmi_sta_ps_mode {/* enable power save for the given STA VDEV */ WMI_STA_PS_MODE_DISABLED =0 ,
Signature · 1 line
2.42.0
Re: [PATCH 4/6] wifi: ath10k: remove unused template structs
Quoted 8 lines · Jeff Johnson
Currently both the
wmi_bcn_tmpl_cmdandwmi_prb_tmpl_cmdstructs define:u8 data[1];Per the guidance in [1] both instances of this should be flexible arrays. However during conversion it was discovered that neither of these structs are actually used, so just remove them.
Quoted 5 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
Signed-off-by Jeff Johnson <[email protected]>
Unused! :)
Signature · 1 line
Kees Cook
Re: [PATCH 4/6] wifi: ath10k: remove unused template structs
In reply to Jeff JohnsonQuoted 8 lines · Jeff Johnson
Currently both the
wmi_bcn_tmpl_cmdandwmi_prb_tmpl_cmdstructs define:u8 data[1];Per the guidance in [1] both instances of this should be flexible arrays. However during conversion it was discovered that neither of these structs are actually used, so just remove them.
Quoted 5 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
Signed-off-by Jeff Johnson <[email protected]>
Thanks!
--
Gustavo
Quoted 40 lines
--- drivers/net/wireless/ath/ath10k/wmi.h | 24 ------------------------ 1 file changed, 24 deletions(-)drivers/net/wireless/ath/ath10k/wmi.h +0
-24@@ -5782,30 +5782,6 @@ struct wmi_bcn_prb_info {/* app IE */ } __packed; -struct wmi_bcn_tmpl_cmd { -/* unique id identifying the VDEV, generated by the caller */ -__le32 vdev_id; -/* TIM IE offset from the beginning of the template. */ -__le32 tim_ie_offset; -/* beacon probe capabilities and IEs */ -struct wmi_bcn_prb_info bcn_prb_info; -/* beacon buffer length */ -__le32 buf_len; -/* variable length data */ -u8 data[1 ]; -} __packed; - -struct wmi_prb_tmpl_cmd { -/* unique id identifying the VDEV, generated by the caller */ -__le32 vdev_id; -/* beacon probe capabilities and IEs */ -struct wmi_bcn_prb_info bcn_prb_info; -/* beacon buffer length */ -__le32 buf_len; -/* Variable length data */ -u8 data[1 ]; -} __packed; -enum wmi_sta_ps_mode {/* enable power save for the given STA VDEV */ WMI_STA_PS_MODE_DISABLED =0 ,
PATCH 5/6 wifi: ath10k: use flexible array in struct wmi_tdls_peer_capabilities
In reply to Jeff JohnsonCurrently struct wmi_tdls_peer_capabilities defines:
struct wmi_channel peer_chan_list[1];
Per the guidance in [1] this should be a flexible array, and at one point Gustavo was trying to fix this [2], but had questions about the correct behavior when the associated peer_chan_len is 0.
I have been unable to determine if firmware requires that at least one record be present even if peer_chan_len is 0. But since that is the current behavior, follow the example from [3] and replace the one-element array with a union that contains both a flexible array and a single instance of the array element. This results in a struct that has the same footprint as the original, so no other driver changes are required.
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://lore.kernel.org/linux-wireless/[email protected]/
[3] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/
--- drivers/net/wireless/ath/ath10k/wmi.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/wmi.h +7 -1
@@ -7162,7 +7162,13 @@ struct wmi_tdls_peer_capabilities {__le32 is_peer_responder;__le32 pref_offchan_num;__le32 pref_offchan_bw; -struct wmi_channel peer_chan_list[1 ]; +union { +/* to match legacy implementation allocate room for +* at least one record even if peer_chan_len is 0 +*/ +struct wmi_channel peer_chan_min_allocation; + DECLARE_FLEX_ARRAY(struct wmi_channel, peer_chan_list); + }; } __packed;struct wmi_10_4_tdls_peer_update_cmd {
Signature · 1 line
2.42.0
Re: [PATCH 5/6] wifi: ath10k: use flexible array in struct wmi_tdls_peer_capabilities
Quoted 15 lines · Jeff Johnson
Currently struct
wmi_tdls_peer_capabilitiesdefines:struct wmi_channel peer_chan_list[1];Per the guidance in [1] this should be a flexible array, and at one point Gustavo was trying to fix this [2], but had questions about the correct behavior when the associated
peer_chan_lenis 0.I have been unable to determine if firmware requires that at least one record be present even if
peer_chan_lenis 0. But since that is the current behavior, follow the example from [3] and replace the one-element array with a union that contains both a flexible array and a single instance of the array element. This results in a struct that has the same footprint as the original, so no other driver changes are required.
Quoted 7 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://lore.kernel.org/linux-wireless/[email protected]/
[3] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/Signed-off-by Jeff Johnson <[email protected]>
Again, good to keep the struct the same size.
Signature · 1 line
Kees Cook
Re: [PATCH 5/6] wifi: ath10k: use flexible array in struct wmi_tdls_peer_capabilities
In reply to Jeff JohnsonQuoted 15 lines · Jeff Johnson
Currently struct
wmi_tdls_peer_capabilitiesdefines:struct wmi_channel peer_chan_list[1];Per the guidance in [1] this should be a flexible array, and at one point Gustavo was trying to fix this [2], but had questions about the correct behavior when the associated
peer_chan_lenis 0.I have been unable to determine if firmware requires that at least one record be present even if
peer_chan_lenis 0. But since that is the current behavior, follow the example from [3] and replace the one-element array with a union that contains both a flexible array and a single instance of the array element. This results in a struct that has the same footprint as the original, so no other driver changes are required.
Quoted 7 lines
No functional changes, compile tested only.
[1] https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://lore.kernel.org/linux-wireless/[email protected]/
[3] https://lore.kernel.org/linux-wireless/202308301529.AC90A9EF98@keescook/Signed-off-by Jeff Johnson <[email protected]>
Thanks!
--
Gustavo
Quoted 24 lines
--- drivers/net/wireless/ath/ath10k/wmi.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/net/wireless/ath/ath10k/wmi.h +7
-1@@ -7162,7 +7162,13 @@ struct wmi_tdls_peer_capabilities {__le32 is_peer_responder;__le32 pref_offchan_num;__le32 pref_offchan_bw; -struct wmi_channel peer_chan_list[1 ]; +union { +/* to match legacy implementation allocate room for +* at least one record even if peer_chan_len is 0 +*/ +struct wmi_channel peer_chan_min_allocation; + DECLARE_FLEX_ARRAY(struct wmi_channel, peer_chan_list); + }; } __packed;struct wmi_10_4_tdls_peer_update_cmd {
PATCH 6/6 wifi: ath10k: remove duplicate memset() in 10.4 TDLS peer update
In reply to Jeff JohnsonIn [1] it was identified that in ath10k_wmi_10_4_gen_tdls_peer_update() the memset(skb->data, 0, sizeof(*cmd)) is unnecessary since function ath10k_wmi_alloc_skb() already zeroes skb->data, so remove it.
No functional changes, compile tested only.
[1] https://lore.kernel.org/linux-wireless/[email protected]/
--- drivers/net/wireless/ath/ath10k/wmi.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/wireless/ath/ath10k/wmi.c +0 -2
@@ -8918,8 +8918,6 @@ ath10k_wmi_10_4_gen_tdls_peer_update(struct ath10k *ar,if (!skb)return ERR_PTR (-ENOMEM ); -memset (skb->data,0 ,sizeof (*cmd)); - cmd = (struct wmi_10_4_tdls_peer_update_cmd *)skb->data; cmd->vdev_id =__cpu_to_le32 (arg->vdev_id);ether_addr_copy (cmd->peer_macaddr.addr, arg->addr);
Signature · 1 line
2.42.0
Re: [PATCH 6/6] wifi: ath10k: remove duplicate memset() in 10.4 TDLS peer update
Quoted 3 lines · Jeff Johnson
In [1] it was identified that in
ath10k_wmi_10_4_gen_tdls_peer_update()thememset(skb->data, 0, sizeof(*cmd))is unnecessary since functionath10k_wmi_alloc_skb()already zeroesskb->data, so remove it.
Is .gen_tdls_peer_update only ever called after a fresh allocation? It wasn't obvious to me as I tried to follow the call paths. Is there harm in leaving this?
-Kees
Quoted 27 lines
No functional changes, compile tested only.
[1] https://lore.kernel.org/linux-wireless/[email protected]/
Signed-off-by Jeff Johnson <[email protected]>--- drivers/net/wireless/ath/ath10k/wmi.c | 2 -- 1 file changed, 2 deletions(-)drivers/net/wireless/ath/ath10k/wmi.c +0
-2@@ -8918,8 +8918,6 @@ ath10k_wmi_10_4_gen_tdls_peer_update(struct ath10k *ar,if (!skb)return ERR_PTR (-ENOMEM ); -memset (skb->data,0 ,sizeof (*cmd)); - cmd = (struct wmi_10_4_tdls_peer_update_cmd *)skb->data; cmd->vdev_id =__cpu_to_le32 (arg->vdev_id);ether_addr_copy (cmd->peer_macaddr.addr, arg->addr);Signature · 2 lines
-- 2.42.0
Signature · 1 line
Kees Cook
Re: [PATCH 6/6] wifi: ath10k: remove duplicate memset() in 10.4 TDLS peer update
Quoted 8 lines · Kees Cook
Quoted 3 lines · Jeff Johnson
In [1] it was identified that in
ath10k_wmi_10_4_gen_tdls_peer_update()thememset(skb->data, 0, sizeof(*cmd))is unnecessary since functionath10k_wmi_alloc_skb()already zeroesskb->data, so remove it.Is .gen_tdls_peer_update only ever called after a fresh allocation? It wasn't obvious to me as I tried to follow the call paths. Is there harm in leaving this?
The only harm is a slight increase in code size and cpu cycles.
However note the skb allocation is done within ath10k_wmi_10_4_gen_tdls_peer_update() itself, just before the code being removed:
skb = ath10k_wmi_alloc_skb(ar, len); if (!skb) return ERR_PTR(-ENOMEM);
And in ath10k_wmi_alloc_skb() we have:
memset(skb->data, 0, round_len);
So the memset() being removed is always redundant.
/jeff
Kees Cook
Reviewed-byRe: [PATCH 6/6] wifi: ath10k: remove duplicate memset() in 10.4 TDLS peer update
Quoted 15 lines · Jeff Johnson
Quoted 8 lines · Kees Cook
Quoted 3 lines · Jeff Johnson
In [1] it was identified that in
ath10k_wmi_10_4_gen_tdls_peer_update()thememset(skb->data, 0, sizeof(*cmd))is unnecessary since functionath10k_wmi_alloc_skb()already zeroesskb->data, so remove it.Is .gen_tdls_peer_update only ever called after a fresh allocation? It wasn't obvious to me as I tried to follow the call paths. Is there harm in leaving this?
The only harm is a slight increase in code size and cpu cycles.
However note the skb allocation is done within
ath10k_wmi_10_4_gen_tdls_peer_update()itself, just before the code being removed:
Quoted 8 lines
skb = ath10k_wmi_alloc_skb(ar, len); if (!skb) return ERR_PTR(-ENOMEM);And in
ath10k_wmi_alloc_skb()we have:memset(skb->data, 0, round_len);So the
memset()being removed is always redundant.
LOL. I see now. I missed that was was looking outside the function! :P
Signature · 1 line
Kees Cook
Re: [PATCH 6/6] wifi: ath10k: remove duplicate memset() in 10.4 TDLS peer update
In reply to Jeff JohnsonQuoted 9 lines · Jeff Johnson
In [1] it was identified that in
ath10k_wmi_10_4_gen_tdls_peer_update()thememset(skb->data, 0, sizeof(*cmd))is unnecessary since functionath10k_wmi_alloc_skb()already zeroesskb->data, so remove it.No functional changes, compile tested only.
[1] https://lore.kernel.org/linux-wireless/[email protected]/
Signed-off-by Jeff Johnson <[email protected]>
Thanks!
--
Gustavo
Quoted 18 lines
--- drivers/net/wireless/ath/ath10k/wmi.c | 2 -- 1 file changed, 2 deletions(-)drivers/net/wireless/ath/ath10k/wmi.c +0
-2@@ -8918,8 +8918,6 @@ ath10k_wmi_10_4_gen_tdls_peer_update(struct ath10k *ar,if (!skb)return ERR_PTR (-ENOMEM ); -memset (skb->data,0 ,sizeof (*cmd)); - cmd = (struct wmi_10_4_tdls_peer_update_cmd *)skb->data; cmd->vdev_id =__cpu_to_le32 (arg->vdev_id);ether_addr_copy (cmd->peer_macaddr.addr, arg->addr);
Quoted 6 lines · Jeff Johnson
Clean up the last remaining zero-length and one-element arrays in ath10k to comply with:
https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arraysWith these cleanups done the ath10k-check script no longer reports any issues.
This is really great!
Thank you for taking care of this. :)
--
Gustavo
Quoted 17 lines
---
Jeff Johnson (6):
wifi: ath10k: use flexible array in structwmi_host_mem_chunks
wifi: ath10k: use flexible arrays for WMI start scan TLVs
wifi: ath10k: remove structwmi_pdev_chanlist_update_event
wifi: ath10k: remove unused template structs
wifi: ath10k: use flexible array in structwmi_tdls_peer_capabilities
wifi: ath10k: remove duplicatememset()in 10.4 TDLS peer updatedrivers/net/wireless/ath/ath10k/wmi.c | 10 +++---- drivers/net/wireless/ath/ath10k/wmi.h | 55 +++++++++-------------------------- 2 files changed, 17 insertions(+), 48 deletions(-)---
base-commit:7133b072dfbfac8763ffb017642c9c894894c50d
change-id: 20231212-wmi_host_mem_chunks_flexarray-78264e146731