mirror of
https://github.com/torvalds/linux.git
synced 2026-05-05 23:05:25 -04:00
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>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
ab67d4c6d5
commit
5ed9ef2703
@@ -114,11 +114,8 @@ static void update_BCNTIM(struct adapter *padapter)
|
||||
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;
|
||||
|
||||
@@ -1442,11 +1439,8 @@ static void update_bcn_wps_ie(struct adapter *padapter)
|
||||
|
||||
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) {
|
||||
|
||||
@@ -1326,10 +1326,9 @@ void rtw_stassoc_event_callback(struct adapter *adapter, u8 *pbuf)
|
||||
/* 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;
|
||||
|
||||
@@ -1323,11 +1323,10 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
|
||||
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 */
|
||||
|
||||
@@ -159,12 +159,10 @@ static void rtl8723bs_c2h_packet_handler(struct adapter *padapter,
|
||||
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)
|
||||
|
||||
@@ -1163,11 +1163,10 @@ static int rtw_cfg80211_set_probe_req_wpsp2pie(struct adapter *padapter, char *b
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,11 +129,9 @@ void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user