[PATCH 6.19 388/844] staging: rtl8723bs: fix memory leak on failure path

From: Sasha Levin

Date: Sat Feb 28 2026 - 13:47:54 EST


From: Diksha Kumari <dikshakdevgan@xxxxxxxxx>

[ Upstream commit abe850d82c8cb72d28700673678724e779b1826e ]

cfg80211_inform_bss_frame() may return NULL on failure. In that case,
the allocated buffer 'buf' is not freed and the function returns early,
leading to potential memory leak.
Fix this by ensuring that 'buf' is freed on both success and failure paths.

Signed-off-by: Diksha Kumari <dikshakdevgan@xxxxxxxxx>
Reviewed-by: Mukesh Kumar Chaurasiya <mkchauras@xxxxxxxxxxxxx>
Link: https://patch.msgid.link/20260113091712.7071-1-dikshakdevgan@xxxxxxxxx
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 60edeae1cffe7..476ab055e53e5 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -315,9 +315,10 @@ struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wl
len, notify_signal, GFP_ATOMIC);

if (unlikely(!bss))
- goto exit;
+ goto free_buf;

cfg80211_put_bss(wiphy, bss);
+free_buf:
kfree(buf);

exit:
--
2.51.0