Skip to contentSkip to conversation

wifi: p54: Use flexible array for channel list

PATCH In review Rosen Penev 2 participants 2 messages May 11 – Sep 4 P54 wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: p54: Use flexible array for channel list

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
---
 drivers/net/wireless/intersil/p54/eeprom.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
drivers/net/wireless/intersil/p54/eeprom.c +7 -13
index 95580921d933..c617bec787a3 100644
@@ -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;
Signature · 1 line
2.54.0
#1 lore raw
Quoted 2 lines · Rosen Penev

Store generated channel entries in the p54 channel list allocation instead of allocating them separately.

Somehow this was still on my list, despite mostly having decided to ignore these __counted_by() things ...

And you clearly didn't even run the code or pay attention to what you were doing, since p54_update_channel_param() has a bug that this would have exposed.

johannes