public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8723bs: Use kmemdup() to replace kzalloc() followed by memcpy()
@ 2026-03-15 19:47 Oarora Etimis
  2026-03-15 21:36 ` Ethan Tidmore
  0 siblings, 1 reply; 2+ messages in thread
From: Oarora Etimis @ 2026-03-15 19:47 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Minu Jin, linux-staging, linux-kernel, 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.

Signed-off-by: Oarora Etimis <OaroraEtimis@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: rtl8723bs: Use kmemdup() to replace kzalloc() followed by memcpy()
  2026-03-15 19:47 [PATCH] staging: rtl8723bs: Use kmemdup() to replace kzalloc() followed by memcpy() Oarora Etimis
@ 2026-03-15 21:36 ` Ethan Tidmore
  0 siblings, 0 replies; 2+ messages in thread
From: Ethan Tidmore @ 2026-03-15 21:36 UTC (permalink / raw)
  To: Oarora Etimis, Greg Kroah-Hartman
  Cc: Minu Jin, linux-staging, linux-kernel, Oarora Etimis

On Sun Mar 15, 2026 at 2:47 PM CDT, Oarora Etimis wrote:
> 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@gmail.com>
> ---

This doesn't apply to staging-next.

>  
> -	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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-15 21:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-15 19:47 [PATCH] staging: rtl8723bs: Use kmemdup() to replace kzalloc() followed by memcpy() Oarora Etimis
2026-03-15 21:36 ` Ethan Tidmore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox