[PATCH 3/4] staging: rtl8723bs: fix NULL deref in c2h_wk_callback() on alloc failure

From: Yi Cong

Date: Tue Jul 28 2026 - 22:35:09 EST


From: Yi Cong <yicong@xxxxxxxxxx>

When the SDIO interrupt handler cannot allocate a c2h event buffer
(GFP_ATOMIC under memory pressure) it pushes NULL onto c2h_queue as a
"needs re-read" marker and wakes c2h_wk. In c2h_wk_callback(), if the
re-allocation also fails, c2h_evt stays NULL and execution falls through
to rtw_hal_c2h_valid(adapter, c2h_evt), whose underlying macro dereferences
c2h_evt->id, causing a NULL pointer dereference panic.

C2H interrupts are produced by firmware/network events at runtime, so this
is reachable under memory pressure. Add a `continue` in the re-allocation
failure branch to give up this event instead of dereferencing NULL.

Fixes: 554c0a3abf21 ("staging: Add rtl8723bs sdio wifi driver")
Signed-off-by: Yi Cong <yicong@xxxxxxxxxx>
---
drivers/staging/rtl8723bs/core/rtw_cmd.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl8723bs/core/rtw_cmd.c
index b932670f5d63..8dc700b9f2e9 100644
--- a/drivers/staging/rtl8723bs/core/rtw_cmd.c
+++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c
@@ -1716,6 +1716,12 @@ static void c2h_wk_callback(struct work_struct *work)
kfree(c2h_evt);
continue;
}
+ } else {
+ /* Give up this event; re-allocation failed. Falling
+ * through would dereference the NULL c2h_evt in
+ * rtw_hal_c2h_valid() below.
+ */
+ continue;
}
}

--
2.25.1