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>
dst_ie = pie + offset;
}
- if (remainder_ielen > 0) {
- pbackup_remainder_ie = rtw_malloc(remainder_ielen);
- if (pbackup_remainder_ie && premainder_ie)
- memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
- }
+ if (premainder_ie && remainder_ielen)
+ pbackup_remainder_ie = kmemdup(premainder_ie, remainder_ielen, GFP_ATOMIC);
*dst_ie++ = WLAN_EID_TIM;
remainder_ielen = ielen - wps_offset - wps_ielen;
- if (remainder_ielen > 0) {
- pbackup_remainder_ie = rtw_malloc(remainder_ielen);
- if (pbackup_remainder_ie)
- memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
- }
+ if (premainder_ie && remainder_ielen)
+ pbackup_remainder_ie = kmemdup(premainder_ie, remainder_ielen, GFP_ATOMIC);
wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {
/* report to upper layer */
spin_lock_bh(&psta->lock);
if (psta->passoc_req && psta->assoc_req_len > 0) {
- passoc_req = rtw_zmalloc(psta->assoc_req_len);
+ passoc_req = kmemdup(psta->passoc_req, psta->assoc_req_len, GFP_ATOMIC);
if (passoc_req) {
assoc_req_len = psta->assoc_req_len;
- memcpy(passoc_req, psta->passoc_req, assoc_req_len);
kfree(psta->passoc_req);
psta->passoc_req = NULL;
spin_lock_bh(&pstat->lock);
kfree(pstat->passoc_req);
pstat->assoc_req_len = 0;
- pstat->passoc_req = rtw_zmalloc(pkt_len);
- if (pstat->passoc_req) {
- memcpy(pstat->passoc_req, pframe, pkt_len);
+ pstat->passoc_req = kmemdup(pframe, pkt_len, GFP_ATOMIC);
+ if (pstat->passoc_req)
pstat->assoc_req_len = pkt_len;
- }
+
spin_unlock_bh(&pstat->lock);
/* 3-(1) report sta add event */
if (length == 0)
return;
- tmp = rtw_zmalloc(length);
+ tmp = kmemdup(pbuf, length, GFP_ATOMIC);
if (!tmp)
return;
- memcpy(tmp, pbuf, length);
-
res = rtw_c2h_packet_wk_cmd(padapter, tmp, length);
if (!res)
pmlmepriv->wps_probe_req_ie = NULL;
}
- pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen);
+ pmlmepriv->wps_probe_req_ie = kmemdup(wps_ie, wps_ielen, GFP_KERNEL);
if (!pmlmepriv->wps_probe_req_ie)
return -EINVAL;
- memcpy(pmlmepriv->wps_probe_req_ie, wps_ie, wps_ielen);
pmlmepriv->wps_probe_req_ie_len = wps_ielen;
}
}
goto keep_ori;
/* duplicate src */
- dup = rtw_malloc(src_len);
- if (dup) {
+ dup = kmemdup(src, src_len, GFP_ATOMIC);
+ if (dup)
dup_len = src_len;
- memcpy(dup, src, dup_len);
- }
keep_ori:
ori = *buf;