[PATCH 3/3] GAS: clean up radio work management

Benjamin Berg benjamin at sipsolutions.net
Wed Feb 18 02:26:07 PST 2026


From: Benjamin Berg <benjamin.berg at intel.com>

By storing the radio work, we can use radio_work_done in all work
removal code paths and get rid of the odd radio_remove_pending_work
function.

Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
Reviewed-by: Andrei Otcheretianski <andrei.otcheretianski at intel.com>
---
 wpa_supplicant/gas_query.c        | 26 ++++++++++----------------
 wpa_supplicant/wpa_supplicant.c   | 17 -----------------
 wpa_supplicant/wpa_supplicant_i.h |  1 -
 3 files changed, 10 insertions(+), 34 deletions(-)

diff --git a/wpa_supplicant/gas_query.c b/wpa_supplicant/gas_query.c
index d201f85539..73cc34e0ab 100644
--- a/wpa_supplicant/gas_query.c
+++ b/wpa_supplicant/gas_query.c
@@ -38,6 +38,7 @@
 struct gas_query_pending {
 	struct dl_list list;
 	struct gas_query *gas;
+	struct wpa_radio_work *work;
 	u8 addr[ETH_ALEN];
 	u8 dialog_token;
 	u8 next_frag_id;
@@ -68,7 +69,6 @@ struct gas_query {
 	struct wpa_supplicant *wpa_s;
 	struct dl_list pending; /* struct gas_query_pending */
 	struct gas_query_pending *current;
-	struct wpa_radio_work *work;
 	struct os_reltime last_mac_addr_rand;
 	int last_rand_sa_type;
 	u8 rand_addr[ETH_ALEN];
@@ -143,12 +143,11 @@ static void gas_query_free(struct gas_query_pending *query, int del_list)
 	if (del_list)
 		dl_list_del(&query->list);
 
-	if (gas->work && gas->work->ctx == query) {
-		radio_work_done(gas->work);
-		gas->work = NULL;
-	} else {
-		radio_remove_pending_work(gas->wpa_s, query);
-	}
+	if (gas->current == query)
+		gas->current = NULL;
+
+	if (query->work)
+		radio_work_done(query->work);
 
 	eloop_cancel_timeout(gas_query_tx_comeback_timeout, gas, query);
 	eloop_cancel_timeout(gas_query_timeout, gas, query);
@@ -169,8 +168,6 @@ static void gas_query_done(struct gas_query *gas,
 		" dialog_token=%u freq=%d status_code=%u result=%s",
 		MAC2STR(query->addr), query->dialog_token, query->freq,
 		query->status_code, gas_result_txt(result));
-	if (gas->current == query)
-		gas->current = NULL;
 	if (query->offchannel_tx_started)
 		offchannel_send_action_done(gas->wpa_s);
 	dl_list_del(&query->list);
@@ -204,7 +201,6 @@ gas_query_get_pending(struct gas_query *gas, const u8 *addr, u8 dialog_token)
 {
 	struct gas_query_pending *q, *alt = NULL;
 	struct wpa_supplicant *wpa_s = gas->wpa_s;
-	void *ctx = gas->work ? gas->work->ctx : NULL;
 
 	/* Prefer a pending entry that matches with the current radio_work to
 	 * avoid issues when freeing the pending entry in gas_query_free(). That
@@ -219,7 +215,7 @@ gas_query_get_pending(struct gas_query *gas, const u8 *addr, u8 dialog_token)
 		    (wpa_s->valid_links &&
 		     ether_addr_equal(wpa_s->ap_mld_addr, addr) &&
 		     wpas_ap_link_address(wpa_s, q->addr))) {
-			if (q == ctx)
+			if (q == gas->current)
 				return q;
 			if (!alt)
 				alt = q;
@@ -717,7 +713,6 @@ static void gas_query_start_cb(struct wpa_radio_work *work, int deinit)
 
 	if (deinit) {
 		if (work->started) {
-			gas->work = NULL;
 			gas_query_done(gas, query, GAS_QUERY_DELETED_AT_DEINIT);
 			return;
 		}
@@ -731,13 +726,11 @@ static void gas_query_start_cb(struct wpa_radio_work *work, int deinit)
 			wpa_msg(wpa_s, MSG_INFO,
 				"Failed to assign random MAC address for GAS");
 			gas_query_free(query, 1);
-			radio_work_done(work);
 			return;
 		}
 		os_memcpy(query->sa, wpa_s->own_addr, ETH_ALEN);
 	}
 
-	gas->work = work;
 	gas_query_tx_initial_req(gas, query);
 }
 
@@ -916,8 +909,9 @@ int gas_query_req(struct gas_query *gas, const u8 *dst, int freq,
 		" dialog_token=%u freq=%d",
 		MAC2STR(query->addr), query->dialog_token, query->freq);
 
-	if (!radio_add_work(gas->wpa_s, freq, "gas-query", 0,
-			    gas_query_start_cb, query)) {
+	query->work = radio_add_work(gas->wpa_s, freq, "gas-query", 0,
+				     gas_query_start_cb, query);
+	if (!query->work) {
 		query->req = NULL; /* caller will free this in error case */
 		gas_query_free(query, 1);
 		return -1;
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 25829d9f68..8bd6f5cb01 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -7387,23 +7387,6 @@ void radio_remove_works(struct wpa_supplicant *wpa_s,
 }
 
 
-void radio_remove_pending_work(struct wpa_supplicant *wpa_s, void *ctx)
-{
-	struct wpa_radio_work *work;
-	struct wpa_radio *radio = wpa_s->radio;
-
-	dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) {
-		if (work->ctx != ctx)
-			continue;
-		wpa_dbg(wpa_s, MSG_DEBUG, "Free pending radio work '%s'@%p%s",
-			work->type, work, work->started ? " (started)" : "");
-		dl_list_del(&work->list);
-		radio_work_free(work);
-		break;
-	}
-}
-
-
 static void radio_remove_pending_connect(struct wpa_supplicant *wpa_s,
 					 const struct wpa_ssid *ssid)
 {
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index be63a10b67..7e36cc300d 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -396,7 +396,6 @@ radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
 void radio_work_done(struct wpa_radio_work *work);
 void radio_remove_works(struct wpa_supplicant *wpa_s,
 			const char *type, int remove_all);
-void radio_remove_pending_work(struct wpa_supplicant *wpa_s, void *ctx);
 void radio_work_check_next(struct wpa_supplicant *wpa_s);
 struct wpa_radio_work *
 radio_work_pending(struct wpa_supplicant *wpa_s, const char *type);
-- 
2.53.0




More information about the Hostap mailing list