brcmfmac: Replace zero-length array with flexible array member
PATCH 1/1 brcmfmac: Replace zero-length array with flexible array member
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use "flexible array members"[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Also, make use of the struct_size() helper in devm_kzalloc().
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#zero-length-and-one-element-arrays
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c | 2 +- include/linux/platform_data/brcmfmac.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +1 -1
@@ -29,7 +29,7 @@ static int brcmf_of_get_country_codes(struct device *dev,return (count == -EINVAL ) ?0 : count; } - cc =devm_kzalloc (dev,sizeof (*cc) + count *sizeof (*cce),GFP_KERNEL ); + cc =devm_kzalloc (dev,struct_size (cc, table, count),GFP_KERNEL );if (!cc)return -ENOMEM ;
include/linux/platform_data/brcmfmac.h +1 -1
@@ -125,7 +125,7 @@ struct brcmfmac_pd_cc_entry {*/ struct brcmfmac_pd_cc {int table_size; -struct brcmfmac_pd_cc_entry table[0 ]; +struct brcmfmac_pd_cc_entry table[]; };/**
--
2.25.1
Quoted 6 lines · Len Baker
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use "flexible array members"[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Quoted 6 lines
Also, make use of the
struct_size()helper indevm_kzalloc().[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#zero-length-and-one-element-arraysSigned-off-by Len Baker <[email protected]>
I'll take this in my -next tree. :)
Thanks, Len.
--
Gustavo
Quoted 34 lines
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c | 2 +- include/linux/platform_data/brcmfmac.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +1
-1@@ -29,7 +29,7 @@ static int brcmf_of_get_country_codes(struct device *dev,return (count == -EINVAL ) ?0 : count; } - cc =devm_kzalloc (dev,sizeof (*cc) + count *sizeof (*cce),GFP_KERNEL ); + cc =devm_kzalloc (dev,struct_size (cc, table, count),GFP_KERNEL );if (!cc)return -ENOMEM ;include/linux/platform_data/brcmfmac.h +1
-2@@ -125,7 +125,7 @@ struct brcmfmac_pd_cc_entry {*/ struct brcmfmac_pd_cc {int table_size; -struct brcmfmac_pd_cc_entry table[0 ]; +struct brcmfmac_pd_cc_entry table[]; };/** -- 2.25.1
Quoted 9 lines · Gustavo A. R. Silva
Quoted 8 lines · Len Baker
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use "flexible array members"[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Also, make use of the
struct_size()helper indevm_kzalloc().
Quoted 8 lines
Quoted 4 lines
[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#zero-length-and-one-element-arraysSigned-off-by Len Baker <[email protected]>Reviewed-by Gustavo A. R. Silva <[email protected]>I'll take this in my -next tree. :)
Why? It should go to wireless-drivers-next.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Quoted 15 lines · Kalle Valo
Quoted 13 lines · Gustavo A. R. Silva
Quoted 12 lines · Len Baker
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use "flexible array members"[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Also, make use of the
struct_size()helper indevm_kzalloc().[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2]
https://www.kernel.org/doc/html/v5.14/process/deprecated.html#zero-length-and-one-element-arrays
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Len Baker <[email protected]>Reviewed-by Gustavo A. R. Silva <[email protected]>I'll take this in my -next tree. :)
Why? It should go to wireless-drivers-next.
Gustavo, so have you dropped this from your tree now? I do not want to get any conflicts because of this.
I'll reiterate again: do not take any patches touching drivers/net/wireless unless I have acked them.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Quoted 2 lines · Kalle Valo
Gustavo, so have you dropped this from your tree now? I do not want to get any conflicts because of this.
It's not on my tree.
Quoted 3 lines
I'll reiterate again: do not take any patches touching
drivers/net/wirelessunless I have acked them.
Got it.
--
Gustavo
Quoted 6 lines · Len Baker
There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use "flexible array members"[1] for these cases. The older style of one-element or zero-length arrays should no longer be used[2].
Quoted 7 lines
Also, make use of the
struct_size()helper indevm_kzalloc().[1] https://en.wikipedia.org/wiki/Flexible_array_member
[2] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#zero-length-and-one-element-arraysSigned-off-by Len Baker <[email protected]>Reviewed-by Gustavo A. R. Silva <[email protected]>
Patch applied to wireless-drivers-next.git, thanks.
3fd445a4d49f brcmfmac: Replace zero-length array with flexible array member
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches