mwifiex_scan_networks() tests adapter->scan_processing without holding any lock and only sets it later under mwifiex_cmd_lock. The test and the set are not atomic, so two callers can both observe the flag clear and both start a scan. This is reachable because callers of this function run in different contexts: mwifiex_cfg80211_scan() runs from a cfg80211 operation, while mwifiex_active_scan_req_for_passive_chan() runs from the driver's main work via mwifiex_check_next_scan_command(), which is not serialized against cfg80211 operations. After the last scan command completes, mwifiex_check_next_scan_command() clears scan_processing and then starts the follow-up hidden SSID scan; a scan request from user space arriving in that window passes the unlocked check as well. Both scans then queue commands on scan_pending_q and share priv->scan_request, so one can clear scan_processing or call cfg80211_scan_done() while the other is still running. Move the scan_processing check under mwifiex_cmd_lock, in the same critical section that sets it, so that test and set are atomic. Signed-off-by: Vishal Gupta --- drivers/net/wireless/marvell/mwifiex/scan.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c b/drivers/net/wireless/marvell/mwifiex/scan.c index bdd4b8465863b..c99c5378b8486 100644 --- a/drivers/net/wireless/marvell/mwifiex/scan.c +++ b/drivers/net/wireless/marvell/mwifiex/scan.c @@ -1499,12 +1499,6 @@ int mwifiex_scan_networks(struct mwifiex_private *priv, u8 scan_current_chan_only; u8 max_chan_per_scan; - if (adapter->scan_processing) { - mwifiex_dbg(adapter, WARN, - "cmd: Scan already in process...\n"); - return -EBUSY; - } - if (priv->scan_block) { mwifiex_dbg(adapter, WARN, "cmd: Scan is blocked during association...\n"); @@ -1519,6 +1513,12 @@ int mwifiex_scan_networks(struct mwifiex_private *priv, } spin_lock_bh(&adapter->mwifiex_cmd_lock); + if (adapter->scan_processing) { + spin_unlock_bh(&adapter->mwifiex_cmd_lock); + mwifiex_dbg(adapter, WARN, + "cmd: Scan already in process...\n"); + return -EBUSY; + } adapter->scan_processing = true; spin_unlock_bh(&adapter->mwifiex_cmd_lock); -- 2.43.0