Commit 5ed9ef27 authored by Minu Jin's avatar Minu Jin Committed by Greg Kroah-Hartman
Browse files

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: default avatarMinu Jin <s9430939@naver.com>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@intel.com>
Link: https://patch.msgid.link/20260204131347.3515949-2-s9430939@naver.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ab67d4c6
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -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) {
+1 −2
Original line number Diff line number Diff line
@@ -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;
+3 −4
Original line number Diff line number Diff line
@@ -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 */
+1 −3
Original line number Diff line number Diff line
@@ -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)
+1 −2
Original line number Diff line number Diff line
@@ -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;
		}
	}
Loading