diff mbox series

[2/3] scan: remove use of wiphy_get_allowed_freqs to optimize 6ghz path

Message ID 20230929161959.3840935-2-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [1/3] wiphy: make wiphy_band_is_disabled return more descriptive | expand

Commit Message

James Prestwood Sept. 29, 2023, 4:19 p.m. UTC
wiphy_get_allowed_freqs was only being used to see if 6GHz was disabled
or not. This is expensive and requires several allocations when there
already exists wiphy_is_band_disabled(). The prior patch modified
wiphy_is_band_disabled() to return -ENOTSUP which allows scan.c to
completely remove the need for wiphy_get_allowed_freqs.

scan_wiphy_watch was also slightly re-ordered to avoid allocating
freqs_6ghz if the scan request was being completed.
---
 src/scan.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/src/scan.c b/src/scan.c
index 93047a6b..57fcae6f 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -574,10 +574,9 @@  static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc,
 	uint32_t bands = BAND_FREQ_2_4_GHZ | BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ;
 	unsigned int i;
 	struct scan_freq_set *subsets[2] = { 0 };
-	_auto_(scan_freq_set_free) struct scan_freq_set *allowed =
-				wiphy_get_allowed_freqs(sc->wiphy, bands);
 	const struct scan_freq_set *supported =
 					wiphy_get_supported_freqs(sc->wiphy);
+	int disabled;
 
 	/*
 	 * No frequencies, just include the entire supported list and let the
@@ -589,8 +588,8 @@  static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc,
 		sr->scan_freqs = scan_freq_set_clone(params->freqs, bands);
 
 	/* If 6GHz is not possible or already allowed don't split the request */
-	if (!(scan_freq_set_get_bands(supported) & BAND_FREQ_6_GHZ) ||
-			(scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ)) {
+	disabled = wiphy_band_is_disabled(sc->wiphy, BAND_FREQ_6_GHZ);
+	if (disabled == -ENOTSUP || disabled == false) {
 		scan_build_next_cmd(sr->cmds, sc, passive,
 						params, sr->scan_freqs);
 		return;
@@ -1947,8 +1946,8 @@  static void scan_wiphy_watch(struct wiphy *wiphy,
 	struct scan_request *sr = NULL;
 	struct l_genl_msg *msg = NULL;
 	struct scan_parameters params = { 0 };
-	struct scan_freq_set *allowed;
 	_auto_(scan_freq_set_free) struct scan_freq_set *freqs_6ghz = NULL;
+	int disabled;
 
 	/* Only care about completed regulatory dumps */
 	if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE)
@@ -1962,18 +1961,19 @@  static void scan_wiphy_watch(struct wiphy *wiphy,
 	if (!sr)
 		return;
 
-	allowed = wiphy_get_allowed_freqs(sc->wiphy, BAND_FREQ_6_GHZ);
-	freqs_6ghz = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_6_GHZ);
-
 	/*
 	 * This update did not allow 6GHz, or the original request was
 	 * not expecting 6GHz. The periodic scan should now be ended.
 	 */
-	if (!allowed || scan_freq_set_isempty(freqs_6ghz) || !sr->split) {
+	disabled = wiphy_band_is_disabled(wiphy, BAND_FREQ_6_GHZ);
+	if (scan_freq_set_get_bands(sr->freqs_scanned) & BAND_FREQ_6_GHZ ||
+			disabled == true || !sr->split) {
 		scan_get_results(sc, sr, sr->freqs_scanned);
-		goto free_allowed;
+		return;
 	}
 
+	freqs_6ghz = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_6_GHZ);
+
 	/*
 	 * At this point we know there is an ongoing periodic scan.
 	 * Create a new 6GHz passive scan request and append to the
@@ -1988,9 +1988,6 @@  static void scan_wiphy_watch(struct wiphy *wiphy,
 	 */
 	if (l_queue_peek_head(sc->requests) == sr)
 		start_next_scan_request(&sr->work);
-
-free_allowed:
-	scan_freq_set_free(allowed);
 }
 
 static struct scan_context *scan_context_new(uint64_t wdev_id)