staging: rtl8723bs: Use kmemdup() to replace kzalloc() followed by memcpy()
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
@@ -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
Quoted 10 lines · Oarora Etimis
The
kzalloc()function allocates memory and zero-initializes it. However, inrtw_cfg80211_set_wpa_ie(), the allocated buffer is immediately overwritten bymemcpy(). This makes the zero-initialization completely unnecessary, wasting CPU cycles.Use
kmemdup()to simplify the code, eliminate the redundantmemcpy(), and remove the unnecessary zeroing overhead.Signed-off-by Oarora Etimis <[email protected]>---
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