[PATCH 1/1] wifi: mwifiex: synchronize scan cancellation state

From: Vishal Gupta

Date: Wed Oct 28 2026 - 10:04:24 EST


Read and update scan_processing under mwifiex_cmd_lock so cancellation
cannot race with scan state changes. Skip scan completion when no scan
was active.

Signed-off-by: Vishal Gupta <vishal.gupta_1@xxxxxxxxxxx>
---
drivers/net/wireless/marvell/mwifiex/scan.c | 34 ++++++++++++---------
1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c b/drivers/net/wireless/marvell/mwifiex/scan.c
index bdd4b8465863b..c2c5738d8a3fa 100644
--- a/drivers/net/wireless/marvell/mwifiex/scan.c
+++ b/drivers/net/wireless/marvell/mwifiex/scan.c
@@ -2059,26 +2059,32 @@ void mwifiex_cancel_scan(struct mwifiex_adapter *adapter)
{
struct mwifiex_private *priv;
int i;
+ bool cancel = false;

mwifiex_cancel_pending_scan_cmd(adapter);

+ spin_lock_bh(&adapter->mwifiex_cmd_lock);
if (adapter->scan_processing) {
- spin_lock_bh(&adapter->mwifiex_cmd_lock);
adapter->scan_processing = false;
- spin_unlock_bh(&adapter->mwifiex_cmd_lock);
- for (i = 0; i < adapter->priv_num; i++) {
- priv = adapter->priv[i];
- if (priv->scan_request) {
- struct cfg80211_scan_info info = {
- .aborted = true,
- };
+ cancel = true;
+ }
+ spin_unlock_bh(&adapter->mwifiex_cmd_lock);

- mwifiex_dbg(adapter, INFO,
- "info: aborting scan\n");
- cfg80211_scan_done(priv->scan_request, &info);
- priv->scan_request = NULL;
- priv->scan_aborting = false;
- }
+ if (!cancel)
+ return;
+
+ for (i = 0; i < adapter->priv_num; i++) {
+ priv = adapter->priv[i];
+ if (priv->scan_request) {
+ struct cfg80211_scan_info info = {
+ .aborted = true,
+ };
+
+ mwifiex_dbg(adapter, INFO,
+ "info: aborting scan\n");
+ cfg80211_scan_done(priv->scan_request, &info);
+ priv->scan_request = NULL;
+ priv->scan_aborting = false;
}
}
}
--
2.43.0