[PATCH 2/3] wpa_supplicant: return newly created radio work

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


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

It is useful to have the newly created radio work so that one can for
example mark it as done before it is even scheduled. Change the return
type in preparation for further cleanups.

Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
Reviewed-by: Andrei Otcheretianski <andrei.otcheretianski at intel.com>
---
 wpa_supplicant/ctrl_iface.c       |  4 ++--
 wpa_supplicant/dpp_supplicant.c   |  4 ++--
 wpa_supplicant/gas_query.c        | 18 +++---------------
 wpa_supplicant/nan_supplicant.c   |  8 ++++----
 wpa_supplicant/p2p_supplicant.c   | 20 ++++++++++----------
 wpa_supplicant/pasn_supplicant.c  |  4 ++--
 wpa_supplicant/pr_supplicant.c    |  4 ++--
 wpa_supplicant/scan.c             |  4 ++--
 wpa_supplicant/sme.c              |  4 ++--
 wpa_supplicant/wpa_supplicant.c   | 19 ++++++++++---------
 wpa_supplicant/wpa_supplicant_i.h |  9 +++++----
 11 files changed, 44 insertions(+), 54 deletions(-)

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index b2b495b907..e6d790d7a9 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -9332,8 +9332,8 @@ static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
 		wpa_s->ext_work_id++;
 	ework->id = wpa_s->ext_work_id;
 
-	if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
-			   ework) < 0) {
+	if (!radio_add_work(wpa_s, freq, ework->type, 0,
+			    wpas_ctrl_radio_work_cb, ework)) {
 		os_free(ework);
 		return -1;
 	}
diff --git a/wpa_supplicant/dpp_supplicant.c b/wpa_supplicant/dpp_supplicant.c
index f7b126e574..ab9d815936 100644
--- a/wpa_supplicant/dpp_supplicant.c
+++ b/wpa_supplicant/dpp_supplicant.c
@@ -1071,8 +1071,8 @@ static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
 		return -1;
 	lwork->freq = freq;
 
-	if (radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
-			   lwork) < 0) {
+	if (!radio_add_work(wpa_s, freq, "dpp-listen", 0, dpp_start_listen_cb,
+			    lwork)) {
 		wpas_dpp_listen_work_free(lwork);
 		return -1;
 	}
diff --git a/wpa_supplicant/gas_query.c b/wpa_supplicant/gas_query.c
index 019d0c1060..d201f85539 100644
--- a/wpa_supplicant/gas_query.c
+++ b/wpa_supplicant/gas_query.c
@@ -47,7 +47,6 @@ struct gas_query_pending {
 	unsigned int wildcard_bssid:1;
 	unsigned int maintain_addr:1;
 	unsigned int sent:1;
-	unsigned int radio_work_removal_scheduled:1;
 	int freq;
 	u16 status_code;
 	struct wpabuf *req;
@@ -147,7 +146,7 @@ static void gas_query_free(struct gas_query_pending *query, int del_list)
 	if (gas->work && gas->work->ctx == query) {
 		radio_work_done(gas->work);
 		gas->work = NULL;
-	} else if (!query->radio_work_removal_scheduled) {
+	} else {
 		radio_remove_pending_work(gas->wpa_s, query);
 	}
 
@@ -717,7 +716,6 @@ static void gas_query_start_cb(struct wpa_radio_work *work, int deinit)
 	struct wpa_supplicant *wpa_s = gas->wpa_s;
 
 	if (deinit) {
-		query->radio_work_removal_scheduled = 1;
 		if (work->started) {
 			gas->work = NULL;
 			gas_query_done(gas, query, GAS_QUERY_DELETED_AT_DEINIT);
@@ -732,7 +730,6 @@ static void gas_query_start_cb(struct wpa_radio_work *work, int deinit)
 		if (wpas_update_random_addr_disassoc(wpa_s) < 0) {
 			wpa_msg(wpa_s, MSG_INFO,
 				"Failed to assign random MAC address for GAS");
-			query->radio_work_removal_scheduled = 1;
 			gas_query_free(query, 1);
 			radio_work_done(work);
 			return;
@@ -919,8 +916,8 @@ 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) < 0) {
+	if (!radio_add_work(gas->wpa_s, freq, "gas-query", 0,
+			    gas_query_start_cb, query)) {
 		query->req = NULL; /* caller will free this in error case */
 		gas_query_free(query, 1);
 		return -1;
@@ -936,15 +933,6 @@ int gas_query_stop(struct gas_query *gas, u8 dialog_token)
 
 	dl_list_for_each(query, &gas->pending, struct gas_query_pending, list) {
 		if (query->dialog_token == dialog_token) {
-			if (!gas->work) {
-				/* The pending radio work has not yet been
-				 * started, but the pending entry has a
-				 * reference to the soon to be freed query.
-				 * Need to remove that radio work now to avoid
-				 * leaving behind a reference to freed memory.
-				 */
-				radio_remove_pending_work(gas->wpa_s, query);
-			}
 			gas_query_done(gas, query, GAS_QUERY_STOPPED);
 			return 0;
 		}
diff --git a/wpa_supplicant/nan_supplicant.c b/wpa_supplicant/nan_supplicant.c
index 70953eccc7..f02b73aee0 100644
--- a/wpa_supplicant/nan_supplicant.c
+++ b/wpa_supplicant/nan_supplicant.c
@@ -438,8 +438,8 @@ static int wpas_nan_de_tx(void *ctx, unsigned int freq, unsigned int wait_time,
 		return -1;
 	}
 
-	if (radio_add_work(wpa_s, freq, "nan-usd-tx", 0,
-			   wpas_nan_usd_start_tx_cb, twork) < 0) {
+	if (!radio_add_work(wpa_s, freq, "nan-usd-tx", 0,
+			    wpas_nan_usd_start_tx_cb, twork)) {
 		wpas_nan_usd_tx_work_free(twork);
 		return -1;
 	}
@@ -529,8 +529,8 @@ static int wpas_nan_de_listen(void *ctx, unsigned int freq,
 	lwork->freq = freq;
 	lwork->duration = duration;
 
-	if (radio_add_work(wpa_s, freq, "nan-usd-listen", 0,
-			   wpas_nan_usd_start_listen_cb, lwork) < 0) {
+	if (!radio_add_work(wpa_s, freq, "nan-usd-listen", 0,
+			    wpas_nan_usd_start_listen_cb, lwork)) {
 		os_free(lwork);
 		return -1;
 	}
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index b7c204edcc..db5ae6a2ca 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -537,8 +537,8 @@ static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
 	wpabuf_free(ies);
 
 	radio_remove_works(wpa_s, "p2p-scan", 0);
-	if (radio_add_work(wpa_s, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb,
-			   params) < 0)
+	if (!radio_add_work(wpa_s, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb,
+			    params))
 		goto fail;
 	return 0;
 
@@ -1824,8 +1824,8 @@ static int wpas_send_action_work(struct wpa_supplicant *wpa_s,
 	awork->wait_time = wait_time;
 	os_memcpy(awork->buf, buf, len);
 
-	if (radio_add_work(wpa_s, freq, "p2p-send-action", 1,
-			   wpas_send_action_cb, awork) < 0) {
+	if (!radio_add_work(wpa_s, freq, "p2p-send-action", 1,
+			    wpas_send_action_cb, awork)) {
 		os_free(awork);
 		return -1;
 	}
@@ -1990,8 +1990,8 @@ static int wpas_p2p_initiate_pasn_auth(struct wpa_supplicant *wpa_s,
 	awork->freq = freq;
 	os_memcpy(awork->peer_addr, peer_addr, ETH_ALEN);
 
-	if (radio_add_work(wpa_s, freq, "p2p-pasn-start-auth", 1,
-			   wpas_p2p_pasn_auth_start_cb, awork) < 0) {
+	if (!radio_add_work(wpa_s, freq, "p2p-pasn-start-auth", 1,
+			    wpas_p2p_pasn_auth_start_cb, awork)) {
 		wpas_p2p_pasn_free_auth_work(awork);
 		return -1;
 	}
@@ -3289,8 +3289,8 @@ static int wpas_start_listen(void *ctx, unsigned int freq,
 		}
 	}
 
-	if (radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb,
-			   lwork) < 0) {
+	if (!radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb,
+			    lwork)) {
 		wpas_p2p_listen_work_free(lwork);
 		return -1;
 	}
@@ -5661,8 +5661,8 @@ static int wpas_p2p_initiate_pasn_verify(struct wpa_supplicant *wpa_s,
 		awork->ssid_len = ssid_len;
 	}
 
-	if (radio_add_work(wpa_s, freq, "p2p-pasn-start-auth", 1,
-			   wpas_p2p_pasn_auth_start_cb, awork) < 0) {
+	if (!radio_add_work(wpa_s, freq, "p2p-pasn-start-auth", 1,
+			    wpas_p2p_pasn_auth_start_cb, awork)) {
 		wpas_p2p_pasn_free_auth_work(awork);
 		return -1;
 	}
diff --git a/wpa_supplicant/pasn_supplicant.c b/wpa_supplicant/pasn_supplicant.c
index 9d93aedbf4..3e8b34eecf 100644
--- a/wpa_supplicant/pasn_supplicant.c
+++ b/wpa_supplicant/pasn_supplicant.c
@@ -865,8 +865,8 @@ int wpas_pasn_auth_start(struct wpa_supplicant *wpa_s,
 		}
 	}
 
-	if (radio_add_work(wpa_s, bss->freq, "pasn-start-auth", 1,
-			   wpas_pasn_auth_start_cb, awork) < 0) {
+	if (!radio_add_work(wpa_s, bss->freq, "pasn-start-auth", 1,
+			    wpas_pasn_auth_start_cb, awork)) {
 		wpas_pasn_free_auth_work(awork);
 		return -1;
 	}
diff --git a/wpa_supplicant/pr_supplicant.c b/wpa_supplicant/pr_supplicant.c
index 79c35e5c35..c50d4bd92d 100644
--- a/wpa_supplicant/pr_supplicant.c
+++ b/wpa_supplicant/pr_supplicant.c
@@ -592,8 +592,8 @@ int wpas_pr_initiate_pasn_auth(struct wpa_supplicant *wpa_s,
 	awork->auth_mode = auth_mode;
 	awork->forced_pr_freq = forced_pr_freq;
 
-	if (radio_add_work(wpa_s, freq, "pr-pasn-start-auth", 1,
-			   wpas_pr_pasn_auth_start_cb, awork) < 0) {
+	if (!radio_add_work(wpa_s, freq, "pr-pasn-start-auth", 1,
+			    wpas_pr_pasn_auth_start_cb, awork)) {
 		wpas_pr_pasn_free_auth_work(awork);
 		return -1;
 	}
diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
index 615bc4b37d..b705058565 100644
--- a/wpa_supplicant/scan.c
+++ b/wpa_supplicant/scan.c
@@ -329,8 +329,8 @@ int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s,
 	}
 
 	if (!ctx ||
-	    radio_add_work(wpa_s, 0, "scan", next, wpas_trigger_scan_cb,
-			   ctx) < 0) {
+	    !radio_add_work(wpa_s, 0, "scan", next, wpas_trigger_scan_cb,
+			    ctx)) {
 		wpa_scan_free_params(ctx);
 		wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_FAILED "ret=-1");
 		return -1;
diff --git a/wpa_supplicant/sme.c b/wpa_supplicant/sme.c
index a3ad073533..e9ebe7eca4 100644
--- a/wpa_supplicant/sme.c
+++ b/wpa_supplicant/sme.c
@@ -1324,8 +1324,8 @@ void sme_authenticate(struct wpa_supplicant *wpa_s,
 	wpa_s->sme.sae_group_index = 0;
 #endif /* CONFIG_SAE */
 
-	if (radio_add_work(wpa_s, bss->freq, "sme-connect", 1,
-			   sme_auth_start_cb, cwork) < 0)
+	if (!radio_add_work(wpa_s, bss->freq, "sme-connect", 1,
+			    sme_auth_start_cb, cwork))
 		wpas_connect_work_free(cwork);
 }
 
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 0cadfc9bb7..25829d9f68 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -2984,8 +2984,8 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
 	cwork->bss = bss;
 	cwork->ssid = ssid;
 
-	if (radio_add_work(wpa_s, bss ? bss->freq : 0, "connect", 1,
-			   wpas_start_assoc_cb, cwork) < 0) {
+	if (!radio_add_work(wpa_s, bss ? bss->freq : 0, "connect", 1,
+			    wpas_start_assoc_cb, cwork)) {
 		os_free(cwork);
 	}
 }
@@ -7479,7 +7479,7 @@ void radio_work_check_next(struct wpa_supplicant *wpa_s)
  * @next: Force as the next work to be executed
  * @cb: Callback function for indicating when radio is available
  * @ctx: Context pointer for the work (work->ctx in cb())
- * Returns: 0 on success, -1 on failure
+ * Returns: pointer to the newly created work, or %NULL on failure
  *
  * This function is used to request time for an operation that requires
  * exclusive radio control. Once the radio is available, the registered callback
@@ -7496,10 +7496,11 @@ void radio_work_check_next(struct wpa_supplicant *wpa_s)
  * Setting this to 0 indicates that the work item may use multiple channels or
  * requires exclusive control of the radio.
  */
-int radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
-		   const char *type, int next,
-		   void (*cb)(struct wpa_radio_work *work, int deinit),
-		   void *ctx)
+struct wpa_radio_work *
+radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
+	       const char *type, int next,
+	       void (*cb)(struct wpa_radio_work *work, int deinit),
+	       void *ctx)
 {
 	struct wpa_radio *radio = wpa_s->radio;
 	struct wpa_radio_work *work;
@@ -7507,7 +7508,7 @@ int radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
 
 	work = os_zalloc(sizeof(*work));
 	if (work == NULL)
-		return -1;
+		return NULL;
 	wpa_dbg(wpa_s, MSG_DEBUG, "Add radio work '%s'@%p", type, work);
 	os_get_reltime(&work->time);
 	work->freq = freq;
@@ -7542,7 +7543,7 @@ int radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
 		radio_work_check_next(wpa_s);
 	}
 
-	return 0;
+	return work;
 }
 
 
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 3693fd298d..be63a10b67 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -388,10 +388,11 @@ struct wpa_radio_work {
 	unsigned int bands;
 };
 
-int radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
-		   const char *type, int next,
-		   void (*cb)(struct wpa_radio_work *work, int deinit),
-		   void *ctx);
+struct wpa_radio_work *
+radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
+	       const char *type, int next,
+	       void (*cb)(struct wpa_radio_work *work, int deinit),
+	       void *ctx);
 void radio_work_done(struct wpa_radio_work *work);
 void radio_remove_works(struct wpa_supplicant *wpa_s,
 			const char *type, int remove_all);
-- 
2.53.0




More information about the Hostap mailing list