[PATCH v2 3/4] WNM: refactor wnm_set_scan_freqs()
Benjamin Berg
benjamin at sipsolutions.net
Tue Aug 5 08:13:16 PDT 2025
From: Avraham Stern <avraham.stern at intel.com>
Use int_array_add_unique() instead of the dedicated add_freq(), which
now can be removed. This also allows removing some local variables
that are no longer needed.
Signed-off-by: Avraham Stern <avraham.stern at intel.com>
Reviewed-by: Otcheretianski, Andrei <andrei.otcheretianski at intel.com>
----
v2:
- Fix string format to use unsigned %zu
Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
---
wpa_supplicant/wnm_sta.c | 21 +++++++--------------
wpa_supplicant/wpa_supplicant.c | 14 --------------
wpa_supplicant/wpa_supplicant_i.h | 1 -
3 files changed, 7 insertions(+), 29 deletions(-)
diff --git a/wpa_supplicant/wnm_sta.c b/wpa_supplicant/wnm_sta.c
index ad7e6933dc..a3de2b2e1d 100644
--- a/wpa_supplicant/wnm_sta.c
+++ b/wpa_supplicant/wnm_sta.c
@@ -1332,8 +1332,6 @@ static int chan_supported(struct wpa_supplicant *wpa_s, int freq)
static void wnm_set_scan_freqs(struct wpa_supplicant *wpa_s)
{
- int *freqs;
- int num_freqs = 0;
unsigned int i;
if (!wpa_s->wnm_neighbor_report_elements)
@@ -1345,10 +1343,6 @@ static void wnm_set_scan_freqs(struct wpa_supplicant *wpa_s)
os_free(wpa_s->next_scan_freqs);
wpa_s->next_scan_freqs = NULL;
- freqs = os_calloc(wpa_s->wnm_num_neighbor_report + 1, sizeof(int));
- if (freqs == NULL)
- return;
-
for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) {
struct neighbor_report *nei;
@@ -1362,22 +1356,21 @@ static void wnm_set_scan_freqs(struct wpa_supplicant *wpa_s)
"WNM: Unknown neighbor operating frequency for "
MACSTR " - scan all channels",
MAC2STR(nei->bssid));
- os_free(freqs);
+ os_free(wpa_s->next_scan_freqs);
+ wpa_s->next_scan_freqs = NULL;
return;
}
if (chan_supported(wpa_s, nei->freq))
- add_freq(freqs, &num_freqs, nei->freq);
+ int_array_add_unique(&wpa_s->next_scan_freqs,
+ nei->freq);
}
- if (num_freqs == 0) {
- os_free(freqs);
+ if (!wpa_s->next_scan_freqs)
return;
- }
wpa_printf(MSG_DEBUG,
- "WNM: Scan %d frequencies based on transition candidate list",
- num_freqs);
- wpa_s->next_scan_freqs = freqs;
+ "WNM: Scan %zu frequencies based on transition candidate list",
+ int_array_len(wpa_s->next_scan_freqs));
}
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index baadc44c0c..14d1e52d6e 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -8764,20 +8764,6 @@ void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s)
}
-void add_freq(int *freqs, int *num_freqs, int freq)
-{
- int i;
-
- for (i = 0; i < *num_freqs; i++) {
- if (freqs[i] == freq)
- return;
- }
-
- freqs[*num_freqs] = freq;
- (*num_freqs)++;
-}
-
-
void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid,
const u8 **link_bssids)
{
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index d8bfcfede9..29d2d80fb9 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -1762,7 +1762,6 @@ int wpas_update_random_addr(struct wpa_supplicant *wpa_s,
enum wpas_mac_addr_style style,
struct wpa_ssid *ssid);
int wpas_update_random_addr_disassoc(struct wpa_supplicant *wpa_s);
-void add_freq(int *freqs, int *num_freqs, int freq);
int wpas_get_op_chan_phy(int freq, const u8 *ies, size_t ies_len,
u8 *op_class, u8 *chan, u8 *phy_type);
--
2.50.1
More information about the Hostap
mailing list