[PATCH rtw-next v3 1/5] wifi: rtw88: free the reserved pages of an interface on firmware recovery

From: Mehmet Fide

Date: Tue Nov 17 2026 - 12:10:22 EST


From: Mehmet Fide <mehmet.fide@xxxxxxxxxxxxxxxxxx>

The recovery after a firmware crash resets the driver state of every
interface, and mac80211 then adds the interfaces again without removing
them first. rtw_ops_add_interface() starts with an empty reserved page
list, so the pages the interface had before the crash are lost: the
next page build takes them off the build list and nothing frees them.

kmemleak after a firmware crash with an AP interface:

unreferenced object 0xffff0000cbe22c60 (size 96):
comm "hostapd", pid 25545, jiffies 4296463067
backtrace (crc cbdc21c4):
kmemleak_alloc+0xcc/0xe4
__kmalloc_cache_noprof+0x234/0x3bc
rtw_add_rsvd_page+0x38/0xa8 [rtw88_core]
rtw_add_rsvd_page_bcn+0x30/0x58 [rtw88_core]
rtw_ops_add_interface+0x144/0x2cc [rtw88_core]
rtw_ops_change_interface+0x6c/0x80 [rtw88_core]
drv_change_interface+0x100/0x258 [mac80211]

Free the pages where the recovery resets the interface.

With the pages freed, a reserved page download before mac80211 adds the
interfaces again finds no page and warns "Should not have an empty
reserved page". The beacon update work queued by rtw_ops_set_tim() and
a beacon change through rtw_ops_bss_info_changed() can both get there:
the recovery drops the driver mutex in rtw_core_stop(), and mac80211
restarts the hardware only after the recovery. The recovery also clears
the port of every interface, and rtw_ops_add_interface() sets it again,
so download nothing and send no page locations while no port is in use.

Fixes: 5c831644e1f4 ("rtw88: handle and recover when firmware crash")
Signed-off-by: Mehmet Fide <mehmet.fide@xxxxxxxxxxxxxxxxxx>
---

Notes:
v3: no RTW_FLAG_RESTARTING test in the beacon update work. The page
download and the page location H2C do nothing while no port is in
use, which also covers a beacon change in the restart window and a
TIM update during the reconfiguration (Luka Gejak)
v2: the beacon update work does nothing while RTW_FLAG_RESTARTING is set
(Luka Gejak): rtw_ops_set_tim() can queue it between the reset and the
reconfiguration, where it found no page and warned

drivers/net/wireless/realtek/rtw88/fw.c | 6 ++++++
drivers/net/wireless/realtek/rtw88/main.c | 1 +
2 files changed, 7 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw88/fw.c b/drivers/net/wireless/realtek/rtw88/fw.c
index 945fedcd375b..c66dc9086378 100644
--- a/drivers/net/wireless/realtek/rtw88/fw.c
+++ b/drivers/net/wireless/realtek/rtw88/fw.c
@@ -1059,6 +1059,9 @@ void rtw_send_rsvd_page_h2c(struct rtw_dev *rtwdev)
u8 h2c_pkt[H2C_PKT_SIZE] = {0};
u8 location = 0;

+ if (bitmap_empty(rtwdev->hw_port, RTW_PORT_NUM))
+ return;
+
SET_H2C_CMD_ID_CLASS(h2c_pkt, H2C_CMD_RSVD_PAGE);

location = rtw_get_rsvd_page_location(rtwdev, RSVD_PROBE_RESP);
@@ -1765,6 +1768,9 @@ int rtw_fw_download_rsvd_page(struct rtw_dev *rtwdev)
u32 size;
int ret;

+ if (bitmap_empty(rtwdev->hw_port, RTW_PORT_NUM))
+ return 0;
+
buf = rtw_build_rsvd_page(rtwdev, &size);
if (!buf) {
rtw_err(rtwdev, "failed to build rsvd page pkt\n");
diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
index f7708ad17b6f..adc54b063382 100644
--- a/drivers/net/wireless/realtek/rtw88/main.c
+++ b/drivers/net/wireless/realtek/rtw88/main.c
@@ -627,6 +627,7 @@ static void rtw_reset_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
rtw_bf_disassoc(rtwdev, vif, NULL);
rtw_vif_assoc_changed(rtwvif, NULL);
rtw_txq_cleanup(rtwdev, vif->txq);
+ rtw_remove_rsvd_page(rtwdev, rtwvif);

rtw_release_macid(rtwdev, rtwvif->mac_id);
}
--
2.56.0