[PATCH] staging: rtl8723bs: Use kmemdup() to replace kzalloc() followed by memcpy()
From: Oarora Etimis
Date: Sun Mar 15 2026 - 15:48:33 EST
The kzalloc() function allocates memory and zero-initializes it.
However, in rtw_cfg80211_set_wpa_ie(), the allocated buffer is
immediately overwritten by memcpy(). This makes the zero-initialization
completely unnecessary, wasting CPU cycles.
Use kmemdup() to simplify the code, eliminate the redundant memcpy(),
and remove the unnecessary zeroing overhead.
Signed-off-by: Oarora Etimis <OaroraEtimis@xxxxxxxxx>
---
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 7cb0c6f22bf3..2f7fa5841578 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -1430,16 +1430,14 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel
goto exit;
}
- buf = kzalloc(ielen, GFP_KERNEL);
+ buf = kmemdup(pie, ielen, GFP_KERNEL);
if (!buf) {
- ret = -ENOMEM;
+ ret = -ENOMEM;
goto exit;
}
- memcpy(buf, pie, ielen);
-
if (ielen < RSN_HEADER_LEN) {
- ret = -1;
+ ret = -1;
goto exit;
}
--
2.47.3