[PATCH 4/9] wpa_supplicant: Add a for_each_valid_links helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Benjamin Berg <benjamin.berg@xxxxxxxxx>

There are quite a few places that need to iterate all valid links and
they all need to check whether the bit is set in wpa_s->valid_links.

Simplify all these places using a simple for_each_valid_links iteration
macro.

Signed-off-by: Benjamin Berg <benjamin.berg@xxxxxxxxx>
---
 wpa_supplicant/bss.c              |  5 +----
 wpa_supplicant/ctrl_iface.c       |  5 +----
 wpa_supplicant/events.c           |  5 +----
 wpa_supplicant/rrm.c              |  5 +----
 wpa_supplicant/sme.c              | 20 +++++---------------
 wpa_supplicant/wnm_sta.c          |  5 +----
 wpa_supplicant/wpa_supplicant.c   |  5 +----
 wpa_supplicant/wpa_supplicant_i.h |  4 ++++
 8 files changed, 15 insertions(+), 39 deletions(-)

diff --git a/wpa_supplicant/bss.c b/wpa_supplicant/bss.c
index 9b37b7a2a..c008d7bdb 100644
--- a/wpa_supplicant/bss.c
+++ b/wpa_supplicant/bss.c
@@ -419,10 +419,7 @@ static int wpa_bss_in_use(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
 	if (!wpa_s->valid_links)
 		return 0;
 
-	for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-		if (!(wpa_s->valid_links & BIT(i)))
-			continue;
-
+	for_each_valid_link(wpa_s, i) {
 		if (ether_addr_equal(bss->bssid, wpa_s->links[i].bssid))
 			return 1;
 	}
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index f3a31160f..bfc9a6631 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -12055,10 +12055,7 @@ static int wpas_ctrl_iface_mlo_status(struct wpa_supplicant *wpa_s,
 	pos = buf;
 	end = buf + buflen;
 
-	for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-		if (!(wpa_s->valid_links & BIT(i)))
-			continue;
-
+	for_each_valid_link(wpa_s, i) {
 		ret = os_snprintf(pos, end - pos, "link_id=%d\nfreq=%u\n"
 				  "ap_link_addr=" MACSTR
 				  "\nsta_link_addr=" MACSTR "\n",
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index a9140a03f..a938bce99 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -4001,10 +4001,7 @@ static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
 	wpa_s->valid_links = mlo.valid_links;
 	wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
 	os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
-	for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-		if (!(wpa_s->valid_links & BIT(i)))
-			continue;
-
+	for_each_valid_link(wpa_s, i) {
 		os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
 		os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
 		wpa_s->links[i].freq = mlo.links[i].freq;
diff --git a/wpa_supplicant/rrm.c b/wpa_supplicant/rrm.c
index 7ce854be0..590c2e5e6 100644
--- a/wpa_supplicant/rrm.c
+++ b/wpa_supplicant/rrm.c
@@ -1520,10 +1520,7 @@ static bool wpas_beacon_rep_scan_match(struct wpa_supplicant *wpa_s,
 	if (!wpa_s->valid_links)
 		return ether_addr_equal(wpa_s->current_bss->bssid, bssid);
 
-	for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-		if (!(wpa_s->valid_links & BIT(i)))
-			continue;
-
+	for_each_valid_link(wpa_s, i) {
 		if (ether_addr_equal(wpa_s->links[i].bssid, bssid))
 			return true;
 	}
diff --git a/wpa_supplicant/sme.c b/wpa_supplicant/sme.c
index 00e1117d5..908b140f8 100644
--- a/wpa_supplicant/sme.c
+++ b/wpa_supplicant/sme.c
@@ -405,10 +405,7 @@ static struct wpa_bss * wpas_ml_connect_pref(struct wpa_supplicant *wpa_s,
 		return bss;
 
 	if (!is_zero_ether_addr(wpa_s->conf->mld_connect_bssid_pref)) {
-		for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-			if (!(wpa_s->valid_links & BIT(i)))
-				continue;
-
+		for_each_valid_link(wpa_s, i) {
 			if (wpa_s->mlo_assoc_link_id == i)
 				continue;
 
@@ -439,10 +436,7 @@ static struct wpa_bss * wpas_ml_connect_pref(struct wpa_supplicant *wpa_s,
 		return bss;
 	}
 
-	for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-		if (!(wpa_s->valid_links & BIT(i)))
-			continue;
-
+	for_each_valid_link(wpa_s, i) {
 		if (wpa_s->mlo_assoc_link_id == i)
 			continue;
 
@@ -2597,10 +2591,7 @@ mscs_fail:
 		params.mld_params.mld_addr = wpa_s->ap_mld_addr;
 		params.mld_params.valid_links = wpa_s->valid_links;
 		params.mld_params.assoc_link_id = wpa_s->mlo_assoc_link_id;
-		for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-			if (!(wpa_s->valid_links & BIT(i)))
-				continue;
-
+		for_each_valid_link(wpa_s, i) {
 			params.mld_params.mld_links[i].bssid =
 				wpa_s->links[i].bssid;
 			params.mld_params.mld_links[i].freq =
@@ -2624,9 +2615,8 @@ mscs_fail:
 			"driver failed");
 
 		/* Prepare list of failed links for error report */
-		for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-			if (!(wpa_s->valid_links & BIT(i)) ||
-			    wpa_s->mlo_assoc_link_id == i ||
+		for_each_valid_link(wpa_s, i) {
+			if (wpa_s->mlo_assoc_link_id == i ||
 			    !params.mld_params.mld_links[i].error)
 				continue;
 
diff --git a/wpa_supplicant/wnm_sta.c b/wpa_supplicant/wnm_sta.c
index db37ccd6e..bf0314454 100644
--- a/wpa_supplicant/wnm_sta.c
+++ b/wpa_supplicant/wnm_sta.c
@@ -2126,10 +2126,7 @@ bool wnm_is_bss_excluded(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
 	if (!wpa_s->valid_links)
 		return false;
 
-	for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-		if (!(wpa_s->valid_links & BIT(i)))
-			continue;
-
+	for_each_valid_link(wpa_s, i) {
 		if (ether_addr_equal(wpa_s->links[i].bssid, bss->bssid)) {
 			wpa_dbg(wpa_s, MSG_DEBUG,
 				"WNM: MLD: Disassociation imminent: current link");
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index cf25df0ec..afe827e01 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -9332,10 +9332,7 @@ bool wpas_ap_link_address(struct wpa_supplicant *wpa_s, const u8 *addr)
 	if (!wpa_s->valid_links)
 		return false;
 
-	for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
-		if (!(wpa_s->valid_links & BIT(i)))
-			continue;
-
+	for_each_valid_link(wpa_s, i) {
 		if (ether_addr_equal(wpa_s->links[i].bssid, addr))
 			return true;
 	}
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 737cae356..ae87bf1e5 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -1603,6 +1603,10 @@ struct wpa_supplicant {
 };
 
 
+#define for_each_valid_link(_wpa_s, _link)				\
+	for ((_link) = 0; (_link) < MAX_NUM_MLD_LINKS; (_link)++)	\
+		if ((_wpa_s)->valid_links & BIT(_link))
+
 /* wpa_supplicant.c */
 void wpa_supplicant_apply_ht_overrides(
 	struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
-- 
2.43.0


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux