Skip to contentSkip to conversation

staging: rtl8723bs: replace kzalloc/kmalloc+memcpy with kmemdup

PATCH Superseded Alexandru Hossu 2 participants 2 messages Mar 4 Staging

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: replace kzalloc/kmalloc+memcpy with kmemdup

Replace kzalloc/kmalloc followed by memcpy with kmemdup to simplify code and avoid unnecessary zero-initialization before overwriting.

From 3ed44dff9cee65557deb3221402a9f8f9cb9957f Mon Sep 17 00:00:00 2001
From: Alexandru Hossu <[email protected]>
Date: Wed, 4 Mar 2026 12:24:33 +0100
Subject: [PATCH] staging: rtl8723bs: replace kzalloc/kmalloc+memcpy with
kmemdup

---
 drivers/staging/rtl8723bs/hal/sdio_ops.c          | 4 +---
 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/hal/sdio_ops.c +1 -3
index c9cb20c61..514c857a9 100644
@@ -583,12 +583,10 @@ s32 sdio_local_write(
 	)
 		return sd_cmd52_write(intfhdl, addr, cnt, buf);
 
-	tmpbuf = kmalloc(cnt, GFP_ATOMIC);
+	tmpbuf = kmemdup(buf, cnt, GFP_ATOMIC);
 	if (!tmpbuf)
 		return -ENOMEM;
 
-	memcpy(tmpbuf, buf, cnt);
-
 	err = sd_write(intfhdl, addr, cnt, tmpbuf);
 
 	kfree(tmpbuf);
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +1 -3
index 7cb0c6f22..2125606f7 100644
@@ -1430,14 +1430,12 @@ 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;
 		goto exit;
 	}
 
-	memcpy(buf, pie, ielen);
-
 	if (ielen < RSN_HEADER_LEN) {
 		ret  = -1;
 		goto exit;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 4 lines · Alexandru Hossu

Replace kzalloc/kmalloc followed by memcpy with kmemdup to simplify code and avoid unnecessary zero-initialization before overwriting.

Please slow down. Also work against staging-next or linux-next.

regards,
dan carpenter