wifi: rsi: fix background scan result and state lifetime
Subsystems (2)
cover wifi: rsi: fix background scan result and state lifetime
Initialize background-scan results and report cancellation as aborted. Report command-preparation failures instead of leaving mac80211 waiting for a completion, then serialize the saved request with cancellation and firmware completion.
The patches are ordered. Patch 2 clears the saved request on every failed start; patch 3 relies on that invariant when it treats bgscan_en and hwscan as one state protected by scan_mutex.
The driver is orphaned and this series was not run on RS9113 or RS9116 hardware. Testing from device users would be helpful.
LLM assistance was used to review this series.
---
The series applies without source changes to the retained 6.1.y, 6.6.y, 6.12.y, 6.18.y, 7.2.10, and v7.3 trees. The retained 5.10.y and 5.15.y trees need a context adaptation in patch 2.
Zhao Li (3):
wifi: rsi: initialize background scan completion data
wifi: rsi: report background scan start failures
wifi: rsi: serialize background scan state
drivers/net/wireless/rsi/rsi_91x_mac80211.c | 50 ++++++++++++++------- drivers/net/wireless/rsi/rsi_91x_main.c | 1 + drivers/net/wireless/rsi/rsi_91x_mgmt.c | 30 ++++++++----- drivers/net/wireless/rsi/rsi_main.h | 2 + drivers/net/wireless/rsi/rsi_mgmt.h | 3 +- 5 files changed, 56 insertions(+), 30 deletions(-)
base-commit: 25e73f1d6868c759c8eb56cad4e411692c5341b4
Signature · 1 line
2.56.0
PATCH 1/3 wifi: rsi: initialize background scan completion data
Background scan completion can expose uninitialized timestamp and BSSID fields to userspace, while cancellation is reported as a successful scan.
Both completion paths allocate cfg80211_scan_info on the stack but set only aborted. mac80211 copies the other fields, and nl80211 can emit the 14 uninitialized bytes when the stack value interpreted as TSF is nonzero.
Zero-initialize the result and mark cancellation aborted.
LLM assistance was used to find the bug and review.
---
Validation: W=1 module builds with MODPOST passed with CONFIG_RSI_COEX enabled and disabled. Not reproduced; RS9113/RS9116 hardware was unavailable.
Sparse C=2 passed. Targeted Smatch introduced no new diagnostics.
drivers/net/wireless/rsi/rsi_91x_mac80211.c | 5 +++-- drivers/net/wireless/rsi/rsi_91x_mgmt.c | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/rsi/rsi_91x_mac80211.c +3 -2
@@ -276,7 +276,9 @@ static void rsi_mac80211_cancel_hw_scan(struct ieee80211_hw *hw, {struct rsi_hw *adapter = hw->priv;struct rsi_common *common = adapter->priv; -struct cfg80211_scan_info info; +struct cfg80211_scan_info info = { + .aborted = true, + };rsi_dbg (INFO_ZONE ,"***** Hardware scan stop *****\n" );mutex_lock (&common->mutex);
@@ -284,7 +286,6 @@ static void rsi_mac80211_cancel_hw_scan(struct ieee80211_hw *hw,if (common->bgscan_en) {if (!rsi_send_bgscan_params (common,RSI_STOP_BGSCAN )) common->bgscan_en = false; - info.aborted = false;ieee80211_scan_completed (adapter->hw, &info);rsi_dbg (INFO_ZONE ,"Back ground scan cancelled\n" ); }
drivers/net/wireless/rsi/rsi_91x_mgmt.c +1 -2
@@ -2107,11 +2107,10 @@ static int rsi_handle_ta_confirm_type(struct rsi_common *common,case BG_SCAN_PROBE_REQ :rsi_dbg (INFO_ZONE ,"BG scan complete event\n" );if (common->bgscan_en) { -struct cfg80211_scan_info info; +struct cfg80211_scan_info info = {};if (!rsi_send_bgscan_params (common,RSI_STOP_BGSCAN )) common->bgscan_en =0 ; - info.aborted = false;ieee80211_scan_completed (adapter->hw, &info); }rsi_dbg (INFO_ZONE ,"Background scan completed\n" );
Signature · 1 line
2.56.0
PATCH 2/3 wifi: rsi: report background scan start failures
In reply to Zhao Lirsi_mac80211_hw_scan_start() returns success when a background-scan command cannot be prepared. The driver never marks the scan active in that case, so neither cancellation nor the firmware-event path reports completion and mac80211 keeps the request pending.
Build the probe request before queueing the start parameters, propagate preparation errors, and clear the saved request before mac80211 frees it. Successful scans keep the existing firmware command order.
LLM assistance was used to find the bug and review.
---
Validation: W=1 module builds with MODPOST passed with CONFIG_RSI_COEX enabled and disabled. Not reproduced; RS9113/RS9116 hardware was unavailable.
Sparse C=2 passed. Targeted Smatch introduced no new diagnostics.
drivers/net/wireless/rsi/rsi_91x_mac80211.c | 14 ++++++++------ drivers/net/wireless/rsi/rsi_91x_mgmt.c | 13 ++++++++----- drivers/net/wireless/rsi/rsi_mgmt.h | 3 +-- 3 files changed, 17 insertions(+), 13 deletions(-)
drivers/net/wireless/rsi/rsi_91x_mac80211.c +8 -6
@@ -237,6 +237,7 @@ static int rsi_mac80211_hw_scan_start(struct ieee80211_hw *hw,struct cfg80211_scan_request *scan_req = &hw_req->req;struct rsi_hw *adapter = hw->priv;struct rsi_common *common = adapter->priv; +int ret;rsi_dbg (INFO_ZONE ,"***** Hardware scan start *****\n" ); common->mac_ops_resumed = false;
@@ -260,15 +261,16 @@ static int rsi_mac80211_hw_scan_start(struct ieee80211_hw *hw,mutex_lock (&common->mutex); common->hwscan = scan_req; -if (!rsi_send_bgscan_params (common,RSI_START_BGSCAN )) { -if (!rsi_send_bgscan_probe_req (common, vif)) { -rsi_dbg (INFO_ZONE ,"Background scan started...\n" ); - common->bgscan_en = true; - } + ret =rsi_start_bgscan (common, vif); +if (ret) { + common->hwscan =NULL ; + }else { +rsi_dbg (INFO_ZONE ,"Background scan started...\n" ); + common->bgscan_en = true; }mutex_unlock (&common->mutex); -return 0 ; +return ret; } static void rsi_mac80211_cancel_hw_scan(struct ieee80211_hw *hw,
drivers/net/wireless/rsi/rsi_91x_mgmt.c +8 -5
@@ -1862,11 +1862,8 @@ int rsi_send_bgscan_params(struct rsi_common *common, int enable)return rsi_send_internal_mgmt_frame (common, skb); } -/* This function sends the probe request to be used by firmware in -* background scan -*/ -int rsi_send_bgscan_probe_req (struct rsi_common *common, -struct ieee80211_vif *vif) +/* Send the firmware commands that start a background scan. */ +int rsi_start_bgscan (struct rsi_common *common,struct ieee80211_vif *vif) {struct cfg80211_scan_request *scan_req = common->hwscan;struct rsi_bgscan_probe *bgscan;
@@ -1875,6 +1872,7 @@ int rsi_send_bgscan_probe_req(struct rsi_common *common,u16 frame_len =sizeof (*bgscan);size_t ssid_len =0 ;u8 *ssid =NULL ; +int ret;rsi_dbg (MGMT_TX_ZONE ,"%s: Sending bgscan probe req frame\n" , __func__);
@@ -1928,6 +1926,11 @@ int rsi_send_bgscan_probe_req(struct rsi_common *common,skb_put (skb, frame_len + probereq_skb->len);dev_kfree_skb (probereq_skb); + ret =rsi_send_bgscan_params (common,RSI_START_BGSCAN ); +if (ret) { +dev_kfree_skb (skb); +return ret; + }return rsi_send_internal_mgmt_frame (common, skb); }
drivers/net/wireless/rsi/rsi_mgmt.h +1 -2
@@ -753,6 +753,5 @@ int rsi_send_ps_request(struct rsi_hw *adapter, bool enable, struct ieee80211_vif *vif);void init_bgscan_params (struct rsi_common *common);int rsi_send_bgscan_params (struct rsi_common *common,int enable); -int rsi_send_bgscan_probe_req (struct rsi_common *common, -struct ieee80211_vif *vif); +int rsi_start_bgscan (struct rsi_common *common,struct ieee80211_vif *vif);#endif
Signature · 1 line
2.56.0
PATCH 3/3 wifi: rsi: serialize background scan state
In reply to Zhao LiThe firmware completion event runs in the RX thread without common->mutex, while scan cancellation can clear hwscan under that mutex. Both paths test bgscan_en before sending STOP and reporting completion. An interleaving can therefore dereference a NULL or freed request in rsi_send_bgscan_params(), or report the scan twice.
The RX path cannot take common->mutex: rsi_mac80211_start() holds it while waiting for that path to finish firmware initialization after hibernation.
Add a scan-specific mutex and use it to serialize start, cancellation, and firmware completion. Clear bgscan_en and hwscan together even when STOP cannot be queued so a later event cannot report the same scan again.
LLM assistance was used to find the bug and review.
---
Validation: W=1 module builds with MODPOST passed with CONFIG_RSI_COEX enabled and disabled. Not reproduced; RS9113/RS9116 hardware was unavailable.
Sparse C=2 passed. Targeted Smatch introduced no new diagnostics. Host state is serialized, but no hardware or protocol evidence established how a late event from a scan whose STOP command was not queued is attributed after a later scan starts.
drivers/net/wireless/rsi/rsi_91x_mac80211.c | 31 +++++++++++++++------ drivers/net/wireless/rsi/rsi_91x_main.c | 1 + drivers/net/wireless/rsi/rsi_91x_mgmt.c | 16 +++++++---- drivers/net/wireless/rsi/rsi_main.h | 2 ++ 4 files changed, 36 insertions(+), 14 deletions(-)
drivers/net/wireless/rsi/rsi_91x_mac80211.c +22 -9
@@ -249,15 +249,21 @@ static int rsi_mac80211_hw_scan_start(struct ieee80211_hw *hw, scan_req->n_channels == 0)return -EINVAL ; +mutex_lock (&common->scan_mutex); +/* Scan already in progress. So return */ -if (common->bgscan_en) -return -EBUSY ; +if (common->bgscan_en) { + ret = -EBUSY ; + goto out; + }/* If STA is not connected, return with special value 1, in order * to start sw_scan in mac80211 */ -if (!vif->cfg.assoc) -return 1 ; +if (!vif->cfg.assoc) { + ret =1 ; + goto out; + }mutex_lock (&common->mutex); common->hwscan = scan_req;
@@ -270,6 +276,9 @@ static int rsi_mac80211_hw_scan_start(struct ieee80211_hw *hw, }mutex_unlock (&common->mutex); +out: +mutex_unlock (&common->scan_mutex); +return ret; }
@@ -283,16 +292,20 @@ static void rsi_mac80211_cancel_hw_scan(struct ieee80211_hw *hw, };rsi_dbg (INFO_ZONE ,"***** Hardware scan stop *****\n" ); -mutex_lock (&common->mutex); +mutex_lock (&common->scan_mutex);if (common->bgscan_en) { -if (!rsi_send_bgscan_params (common,RSI_STOP_BGSCAN )) - common->bgscan_en = false; +mutex_lock (&common->mutex); +if (rsi_send_bgscan_params (common,RSI_STOP_BGSCAN )) +rsi_dbg (ERR_ZONE ,"Failed to stop background scan\n" ); +mutex_unlock (&common->mutex); + common->bgscan_en = false; + common->hwscan =NULL ;ieee80211_scan_completed (adapter->hw, &info);rsi_dbg (INFO_ZONE ,"Back ground scan cancelled\n" ); } - common->hwscan =NULL ; -mutex_unlock (&common->mutex); + +mutex_unlock (&common->scan_mutex); }/**
drivers/net/wireless/rsi/rsi_91x_main.c +1 -0
@@ -325,6 +325,7 @@ struct rsi_hw *rsi_91x_init(u16 oper_mode)rsi_init_event (&common->tx_thread.event);mutex_init (&common->mutex); +mutex_init (&common->scan_mutex);mutex_init (&common->tx_lock);mutex_init (&common->rx_lock);mutex_init (&common->tx_bus_mutex);
drivers/net/wireless/rsi/rsi_91x_mgmt.c +11 -5
@@ -2107,17 +2107,23 @@ static int rsi_handle_ta_confirm_type(struct rsi_common *common,rsi_dbg (INFO_ZONE ,"Wakeup/Sleep confirmation.\n" );return rsi_handle_ps_confirm (adapter, msg); -case BG_SCAN_PROBE_REQ : +case BG_SCAN_PROBE_REQ : { +struct cfg80211_scan_info info = {}; +rsi_dbg (INFO_ZONE ,"BG scan complete event\n" ); +mutex_lock (&common->scan_mutex);if (common->bgscan_en) { -struct cfg80211_scan_info info = {}; - -if (!rsi_send_bgscan_params (common,RSI_STOP_BGSCAN )) - common->bgscan_en =0 ; +if (rsi_send_bgscan_params (common,RSI_STOP_BGSCAN )) +rsi_dbg (ERR_ZONE , +"Failed to stop background scan\n" ); + common->bgscan_en = false; + common->hwscan =NULL ;ieee80211_scan_completed (adapter->hw, &info); } +mutex_unlock (&common->scan_mutex);rsi_dbg (INFO_ZONE ,"Background scan completed\n" );break ; + }default : rsi_dbg(INFO_ZONE, "%s: Invalid TA confirm pkt received\n",
drivers/net/wireless/rsi/rsi_main.h +2 -0
@@ -250,6 +250,8 @@ struct rsi_common {struct completion wlan_init_completion;/* Mutex declaration */ struct mutex mutex; +/* Protect background scan state. */ +struct mutex scan_mutex;/* Mutex used for tx thread */ struct mutex tx_lock;/* Mutex used for rx thread */
Signature · 1 line
2.56.0