Skip to contentSkip to conversation

staging: rtl8723bs: Use kmemdup() to replace kzalloc() followed by memcpy()

PATCH In review Oarora Etimis 2 participants 2 messages Mar 15 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: Use kmemdup() to replace kzalloc() followed by memcpy()

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.

---
 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +3 -5
index 7cb0c6f22bf3..2f7fa5841578 100644
@@ -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;
 	}
 
Signature · 1 line
2.47.3
#1 lore raw
Quoted 10 lines · Oarora Etimis

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.

---

This doesn't apply to staging-next.

drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel · line 1442

Quoted 9 lines
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +1 -3
-	memcpy(buf, pie, ielen);
-
 	if (ielen < RSN_HEADER_LEN) {
-		ret  = -1;
+		ret = -1;
 		goto exit;
 	}

Also, this is a stray change. Keep one logical change per patch.

Thanks,

ET