Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

staging: rtl8723bs: introduce kmemdup() where applicable

Replace memory allocation followed by memcpy() with kmemdup() to simplify
the code and improve readability.

About GFP Flags:
- GFP_ATOMIC is used for allocations in atomic contexts such as
spinlock-protected sections, tasklets, and timer handlers.
- GFP_KERNEL is used for process contexts where sleeping is allowed.

Specifically, in OnAssocReq(), GFP_ATOMIC is used because
the allocation is performed while holding a spin lock.

Signed-off-by: Minu Jin <s9430939@naver.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Link: https://patch.msgid.link/20260204131347.3515949-2-s9430939@naver.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Minu Jin and committed by
Greg Kroah-Hartman
5ed9ef27 ab67d4c6

+12 -25
+4 -10
drivers/staging/rtl8723bs/core/rtw_ap.c
··· 114 114 dst_ie = pie + offset; 115 115 } 116 116 117 - if (remainder_ielen > 0) { 118 - pbackup_remainder_ie = rtw_malloc(remainder_ielen); 119 - if (pbackup_remainder_ie && premainder_ie) 120 - memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen); 121 - } 117 + if (premainder_ie && remainder_ielen) 118 + pbackup_remainder_ie = kmemdup(premainder_ie, remainder_ielen, GFP_ATOMIC); 122 119 123 120 *dst_ie++ = WLAN_EID_TIM; 124 121 ··· 1439 1442 1440 1443 remainder_ielen = ielen - wps_offset - wps_ielen; 1441 1444 1442 - if (remainder_ielen > 0) { 1443 - pbackup_remainder_ie = rtw_malloc(remainder_ielen); 1444 - if (pbackup_remainder_ie) 1445 - memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen); 1446 - } 1445 + if (premainder_ie && remainder_ielen) 1446 + pbackup_remainder_ie = kmemdup(premainder_ie, remainder_ielen, GFP_ATOMIC); 1447 1447 1448 1448 wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */ 1449 1449 if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
+1 -2
drivers/staging/rtl8723bs/core/rtw_mlme.c
··· 1326 1326 /* report to upper layer */ 1327 1327 spin_lock_bh(&psta->lock); 1328 1328 if (psta->passoc_req && psta->assoc_req_len > 0) { 1329 - passoc_req = rtw_zmalloc(psta->assoc_req_len); 1329 + passoc_req = kmemdup(psta->passoc_req, psta->assoc_req_len, GFP_ATOMIC); 1330 1330 if (passoc_req) { 1331 1331 assoc_req_len = psta->assoc_req_len; 1332 - memcpy(passoc_req, psta->passoc_req, assoc_req_len); 1333 1332 1334 1333 kfree(psta->passoc_req); 1335 1334 psta->passoc_req = NULL;
+3 -4
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
··· 1323 1323 spin_lock_bh(&pstat->lock); 1324 1324 kfree(pstat->passoc_req); 1325 1325 pstat->assoc_req_len = 0; 1326 - pstat->passoc_req = rtw_zmalloc(pkt_len); 1327 - if (pstat->passoc_req) { 1328 - memcpy(pstat->passoc_req, pframe, pkt_len); 1326 + pstat->passoc_req = kmemdup(pframe, pkt_len, GFP_ATOMIC); 1327 + if (pstat->passoc_req) 1329 1328 pstat->assoc_req_len = pkt_len; 1330 - } 1329 + 1331 1330 spin_unlock_bh(&pstat->lock); 1332 1331 1333 1332 /* 3-(1) report sta add event */
+1 -3
drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c
··· 159 159 if (length == 0) 160 160 return; 161 161 162 - tmp = rtw_zmalloc(length); 162 + tmp = kmemdup(pbuf, length, GFP_ATOMIC); 163 163 if (!tmp) 164 164 return; 165 - 166 - memcpy(tmp, pbuf, length); 167 165 168 166 res = rtw_c2h_packet_wk_cmd(padapter, tmp, length); 169 167
+1 -2
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
··· 1163 1163 pmlmepriv->wps_probe_req_ie = NULL; 1164 1164 } 1165 1165 1166 - pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen); 1166 + pmlmepriv->wps_probe_req_ie = kmemdup(wps_ie, wps_ielen, GFP_KERNEL); 1167 1167 if (!pmlmepriv->wps_probe_req_ie) 1168 1168 return -EINVAL; 1169 1169 1170 - memcpy(pmlmepriv->wps_probe_req_ie, wps_ie, wps_ielen); 1171 1170 pmlmepriv->wps_probe_req_ie_len = wps_ielen; 1172 1171 } 1173 1172 }
+2 -4
drivers/staging/rtl8723bs/os_dep/osdep_service.c
··· 129 129 goto keep_ori; 130 130 131 131 /* duplicate src */ 132 - dup = rtw_malloc(src_len); 133 - if (dup) { 132 + dup = kmemdup(src, src_len, GFP_ATOMIC); 133 + if (dup) 134 134 dup_len = src_len; 135 - memcpy(dup, src, dup_len); 136 - } 137 135 138 136 keep_ori: 139 137 ori = *buf;