[PATCH wireless-next] wifi: p54: Use flexible array for channel list

Rosen Penev posted 1 patch 1 month ago
drivers/net/wireless/intersil/p54/eeprom.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
[PATCH wireless-next] wifi: p54: Use flexible array for channel list
Posted by Rosen Penev 1 month ago
Store generated channel entries in the p54 channel list allocation
instead of allocating them separately.

This ties the temporary channel entries to the list lifetime, removes a
separate allocation failure path, and lets __counted_by() describe the
array bounds.

Assisted-by: Codex:GPT-5.5
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/wireless/intersil/p54/eeprom.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/net/wireless/intersil/p54/eeprom.c b/drivers/net/wireless/intersil/p54/eeprom.c
index 95580921d933..c617bec787a3 100644
--- a/drivers/net/wireless/intersil/p54/eeprom.c
+++ b/drivers/net/wireless/intersil/p54/eeprom.c
@@ -77,10 +77,10 @@ struct p54_channel_entry {
 };
 
 struct p54_channel_list {
-	struct p54_channel_entry *channels;
 	size_t entries;
 	size_t max_entries;
 	size_t band_channel_num[NUM_NL80211_BANDS];
+	struct p54_channel_entry channels[] __counted_by(max_entries);
 };
 
 static int p54_get_band_from_freq(u16 freq)
@@ -335,24 +335,21 @@ static int p54_generate_channel_lists(struct ieee80211_hw *dev)
 	max_channel_num = max_t(unsigned int, max_channel_num,
 				priv->curve_data->entries);
 
-	list = kzalloc_obj(*list);
+	list = kzalloc_flex(*list, channels, max_channel_num);
 	if (!list) {
 		ret = -ENOMEM;
 		goto free;
 	}
-	priv->chan_num = max_channel_num;
+
+	list->max_entries = max_channel_num;
+
 	priv->survey = kzalloc_objs(struct survey_info, max_channel_num);
 	if (!priv->survey) {
 		ret = -ENOMEM;
 		goto free;
 	}
 
-	list->max_entries = max_channel_num;
-	list->channels = kzalloc_objs(struct p54_channel_entry, max_channel_num);
-	if (!list->channels) {
-		ret = -ENOMEM;
-		goto free;
-	}
+	priv->chan_num = max_channel_num;
 
 	for (i = 0; i < max_channel_num; i++) {
 		if (i < priv->iq_autocal_len) {
@@ -401,10 +398,7 @@ static int p54_generate_channel_lists(struct ieee80211_hw *dev)
 	}
 
 free:
-	if (list) {
-		kfree(list->channels);
-		kfree(list);
-	}
+	kfree(list);
 	if (ret) {
 		kfree(priv->survey);
 		priv->survey = NULL;
-- 
2.54.0