2023-12-13 17:07:46

by Jeff Johnson

[permalink] [raw]
Subject: [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/

Signed-off-by: Jeff Johnson <[email protected]>
---
drivers/net/wireless/ath/ath10k/wmi.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath10k/wmi.h b/drivers/net/wireless/ath/ath10k/wmi.h
index 9146df98fcee..833ce0251a2c 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.h
+++ b/drivers/net/wireless/ath/ath10k/wmi.h
@@ -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 {

--
2.42.0



2023-12-13 19:10:33

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH 1/6] wifi: ath10k: use flexible array in struct wmi_host_mem_chunks

On Wed, Dec 13, 2023 at 09:06:39AM -0800, Jeff Johnson wrote:
> 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/
>
> Signed-off-by: Jeff Johnson <[email protected]>

This looks like the right approach here.

Reviewed-by: Kees Cook <[email protected]>

--
Kees Cook

2023-12-13 20:15:03

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH 1/6] wifi: ath10k: use flexible array in struct wmi_host_mem_chunks



On 12/13/23 11:06, Jeff Johnson wrote:
> 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/
>
> Signed-off-by: Jeff Johnson <[email protected]>

Reviewed-by: Gustavo A. R. Silva <[email protected]>

Thanks!
--
Gustavo

> ---
> drivers/net/wireless/ath/ath10k/wmi.h | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/ath/ath10k/wmi.h b/drivers/net/wireless/ath/ath10k/wmi.h
> index 9146df98fcee..833ce0251a2c 100644
> --- a/drivers/net/wireless/ath/ath10k/wmi.h
> +++ b/drivers/net/wireless/ath/ath10k/wmi.h
> @@ -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 {
>

2023-12-18 18:47:34

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH 1/6] wifi: ath10k: use flexible array in struct wmi_host_mem_chunks

Jeff Johnson <[email protected]> wrote:

> 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/
>
> 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

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


2023-12-18 18:51:42

by Gustavo A. R. Silva

[permalink] [raw]
Subject: Re: [PATCH 1/6] wifi: ath10k: use flexible array in struct wmi_host_mem_chunks


> 6 patches applied to ath-next branch of ath.git, thanks.

Awesome! :)

Thanks
--
Gustavo