Skip to contentSkip to conversation

brcmfmac: Replace zero-length array with flexible array member

PATCH In review Len Baker 4 participants 6 messages Sep 4, 2021 – Sep 24, 2021

Subsystems (3)
lore
Share & tools
lore

Len Baker

author
#0 lore raw

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
index 2f7bc3a70c65..513c7e6421b2 100644
@@ -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
index 1d30bf278231..2b5676ff35be 100644
@@ -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

Reviewed-by on v1 1/1
#1 lore raw
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 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

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
index 2f7bc3a70c65..513c7e6421b2 100644
@@ -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
index 1d30bf278231..2b5676ff35be 100644
@@ -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

#2 lore raw
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 in devm_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-arrays

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
#3 lore raw
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 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

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

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
#4 lore raw
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/wireless unless I have acked them.

Got it.

--
Gustavo

#5 lore raw
In reply to Len Baker
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 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

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