git: 62abea27d700 - stable/13 - net80211: ieee80211_swscan_bg_scan() track return variable under lock

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Wed, 29 Nov 2023 16:37:49 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=62abea27d7006bd1caaf25faef713c61047fa9be

commit 62abea27d7006bd1caaf25faef713c61047fa9be
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2023-02-18 01:15:21 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-11-29 16:36:03 +0000

    net80211: ieee80211_swscan_bg_scan() track return variable under lock
    
    As the comment says it probably does not matter but use a local
    variable to track state under lock so we can return the last known
    good state of what we thought we were operating under after unlocking.
    
    Likely no functional changes.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit c9ba91435a01a80632a5b68144d75b38241fc8be)
---
 sys/net80211/ieee80211_scan_sw.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys/net80211/ieee80211_scan_sw.c b/sys/net80211/ieee80211_scan_sw.c
index af90a72d4adb..3a29a784f36b 100644
--- a/sys/net80211/ieee80211_scan_sw.c
+++ b/sys/net80211/ieee80211_scan_sw.c
@@ -332,12 +332,14 @@ ieee80211_swscan_bg_scan(const struct ieee80211_scanner *scan,
 {
 	struct ieee80211com *ic = vap->iv_ic;
 	struct ieee80211_scan_state *ss = ic->ic_scan;
+	bool scanning;
 
 	/* XXX assert unlocked? */
 	// IEEE80211_UNLOCK_ASSERT(ic);
 
 	IEEE80211_LOCK(ic);
-	if ((ic->ic_flags & IEEE80211_F_SCAN) == 0) {
+	scanning = ic->ic_flags & IEEE80211_F_SCAN;
+	if (!scanning) {
 		u_int duration;
 		/*
 		 * Go off-channel for a fixed interval that is large
@@ -401,6 +403,7 @@ ieee80211_swscan_bg_scan(const struct ieee80211_scanner *scan,
 			ic->ic_flags_ext |= IEEE80211_FEXT_BGSCAN;
 			ieee80211_runtask(ic,
 			    &SCAN_PRIVATE(ss)->ss_scan_start);
+			scanning = true;
 		} else {
 			/* XXX msg+stat */
 		}
@@ -411,8 +414,7 @@ ieee80211_swscan_bg_scan(const struct ieee80211_scanner *scan,
 	}
 	IEEE80211_UNLOCK(ic);
 
-	/* NB: racey, does it matter? */
-	return (ic->ic_flags & IEEE80211_F_SCAN);
+	return (scanning);
 }
 
 /*