Skip to content

Commit 5ed9ef2

Browse files
Jminugregkh
authored andcommitted
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>
1 parent ab67d4c commit 5ed9ef2

6 files changed

Lines changed: 12 additions & 25 deletions

File tree

drivers/staging/rtl8723bs/core/rtw_ap.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,8 @@ static void update_BCNTIM(struct adapter *padapter)
114114
dst_ie = pie + offset;
115115
}
116116

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);
122119

123120
*dst_ie++ = WLAN_EID_TIM;
124121

@@ -1442,11 +1439,8 @@ static void update_bcn_wps_ie(struct adapter *padapter)
14421439

14431440
remainder_ielen = ielen - wps_offset - wps_ielen;
14441441

1445-
if (remainder_ielen > 0) {
1446-
pbackup_remainder_ie = rtw_malloc(remainder_ielen);
1447-
if (pbackup_remainder_ie)
1448-
memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
1449-
}
1442+
if (premainder_ie && remainder_ielen)
1443+
pbackup_remainder_ie = kmemdup(premainder_ie, remainder_ielen, GFP_ATOMIC);
14501444

14511445
wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
14521446
if ((wps_offset + wps_ielen + 2 + remainder_ielen) <= MAX_IE_SZ) {

drivers/staging/rtl8723bs/core/rtw_mlme.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,10 +1326,9 @@ void rtw_stassoc_event_callback(struct adapter *adapter, u8 *pbuf)
13261326
/* report to upper layer */
13271327
spin_lock_bh(&psta->lock);
13281328
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);
13301330
if (passoc_req) {
13311331
assoc_req_len = psta->assoc_req_len;
1332-
memcpy(passoc_req, psta->passoc_req, assoc_req_len);
13331332

13341333
kfree(psta->passoc_req);
13351334
psta->passoc_req = NULL;

drivers/staging/rtl8723bs/core/rtw_mlme_ext.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,11 +1323,10 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
13231323
spin_lock_bh(&pstat->lock);
13241324
kfree(pstat->passoc_req);
13251325
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)
13291328
pstat->assoc_req_len = pkt_len;
1330-
}
1329+
13311330
spin_unlock_bh(&pstat->lock);
13321331

13331332
/* 3-(1) report sta add event */

drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,10 @@ static void rtl8723bs_c2h_packet_handler(struct adapter *padapter,
159159
if (length == 0)
160160
return;
161161

162-
tmp = rtw_zmalloc(length);
162+
tmp = kmemdup(pbuf, length, GFP_ATOMIC);
163163
if (!tmp)
164164
return;
165165

166-
memcpy(tmp, pbuf, length);
167-
168166
res = rtw_c2h_packet_wk_cmd(padapter, tmp, length);
169167

170168
if (!res)

drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,11 +1163,10 @@ static int rtw_cfg80211_set_probe_req_wpsp2pie(struct adapter *padapter, char *b
11631163
pmlmepriv->wps_probe_req_ie = NULL;
11641164
}
11651165

1166-
pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen);
1166+
pmlmepriv->wps_probe_req_ie = kmemdup(wps_ie, wps_ielen, GFP_KERNEL);
11671167
if (!pmlmepriv->wps_probe_req_ie)
11681168
return -EINVAL;
11691169

1170-
memcpy(pmlmepriv->wps_probe_req_ie, wps_ie, wps_ielen);
11711170
pmlmepriv->wps_probe_req_ie_len = wps_ielen;
11721171
}
11731172
}

drivers/staging/rtl8723bs/os_dep/osdep_service.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,9 @@ void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
129129
goto keep_ori;
130130

131131
/* duplicate src */
132-
dup = rtw_malloc(src_len);
133-
if (dup) {
132+
dup = kmemdup(src, src_len, GFP_ATOMIC);
133+
if (dup)
134134
dup_len = src_len;
135-
memcpy(dup, src, dup_len);
136-
}
137135

138136
keep_ori:
139137
ori = *buf;

0 commit comments

Comments
 (0)