Skip to content

Commit

Permalink
staging: r8188eu: Remove wrappers for kalloc() and kzalloc()
Browse files Browse the repository at this point in the history
These wrappers involve an in_interrupt() call, which is not frowned on
in the kernel. These changes decrease the size of the driver by a trivial
amount.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Link: https://lore.kernel.org/r/20210805183717.23007-2-Larry.Finger@lwfinger.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
lwfinger authored and gregkh committed Aug 5, 2021
1 parent 66e9564 commit 79f712e
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 115 deletions.
8 changes: 4 additions & 4 deletions drivers/staging/r8188eu/core/rtw_ap.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void update_BCNTIM(struct adapter *padapter)
}

if (remainder_ielen > 0) {
pbackup_remainder_ie = rtw_malloc(remainder_ielen);
pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_KERNEL);
if (pbackup_remainder_ie && premainder_ie)
memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ void rtw_add_bcn_ie(struct adapter *padapter, struct wlan_bssid_ex *pnetwork, u8
}

if (remainder_ielen > 0) {
pbackup_remainder_ie = rtw_malloc(remainder_ielen);
pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_KERNEL);
if (pbackup_remainder_ie && premainder_ie)
memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
}
Expand Down Expand Up @@ -224,7 +224,7 @@ void rtw_remove_bcn_ie(struct adapter *padapter, struct wlan_bssid_ex *pnetwork,
}

if (remainder_ielen > 0) {
pbackup_remainder_ie = rtw_malloc(remainder_ielen);
pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_KERNEL);
if (pbackup_remainder_ie && premainder_ie)
memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
}
Expand Down Expand Up @@ -1302,7 +1302,7 @@ 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);
pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_KERNEL);
if (pbackup_remainder_ie)
memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/r8188eu/core/rtw_br_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ static void __nat25_db_network_insert(struct adapter *priv,
}
db = db->next_hash;
}
db = (struct nat25_network_db_entry *) rtw_malloc(sizeof(*db));
db = kmalloc(sizeof(*db), GFP_KERNEL);
if (!db) {
spin_unlock_bh(&priv->br_ext_lock);
return;
Expand Down
11 changes: 7 additions & 4 deletions drivers/staging/r8188eu/core/rtw_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1947,10 +1947,13 @@ static void c2h_wk_callback(struct work_struct *work)
if ((c2h_evt = (struct c2h_evt_hdr *)rtw_cbuf_pop(evtpriv->c2h_queue)) != NULL) {
/* This C2H event is read, clear it */
c2h_evt_clear(adapter);
} else if ((c2h_evt = (struct c2h_evt_hdr *)rtw_malloc(16)) != NULL) {
/* This C2H event is not read, read & clear now */
if (c2h_evt_read(adapter, (u8 *)c2h_evt) != _SUCCESS)
continue;
} else {
c2h_evt = kmalloc(16, GFP_KERNEL);
if (c2h_evt) {
/* This C2H event is not read, read & clear now */
if (c2h_evt_read(adapter, (u8 *)c2h_evt) != _SUCCESS)
continue;
}
}

/* Special pointer to trigger c2h_evt_clear only */
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/r8188eu/core/rtw_efuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ u8 rtw_efuse_map_write(struct adapter *padapter, u16 addr, u16 cnts, u8 *data)
if ((addr + cnts) > mapLen)
return _FAIL;

map = rtw_zmalloc(mapLen);
map = kzalloc(mapLen, GFP_KERNEL);
if (!map)
return _FAIL;

Expand Down Expand Up @@ -625,7 +625,7 @@ u8 rtw_BT_efuse_map_write(struct adapter *padapter, u16 addr, u16 cnts, u8 *data
if ((addr + cnts) > mapLen)
return _FAIL;

map = rtw_zmalloc(mapLen);
map = kzalloc(mapLen, GFP_KERNEL);
if (!map)
return _FAIL;

Expand Down
8 changes: 4 additions & 4 deletions drivers/staging/r8188eu/core/rtw_mlme.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,13 +1735,13 @@ int rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv)
struct cmd_priv *pcmdpriv = &(adapter->cmdpriv);
int res = _SUCCESS;

pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
pcmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
if (!pcmd) {
res = _FAIL; /* try again */
goto exit;
}

psetauthparm = (struct setauth_parm *)rtw_zmalloc(sizeof(struct setauth_parm));
psetauthparm = kzalloc(sizeof(struct setauth_parm), GFP_KERNEL);
if (!psetauthparm) {
kfree(pcmd);
res = _FAIL;
Expand Down Expand Up @@ -1773,12 +1773,12 @@ int rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv, in
struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
int res = _SUCCESS;

pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
pcmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
if (!pcmd) {
res = _FAIL; /* try again */
goto exit;
}
psetkeyparm = (struct setkey_parm *)rtw_zmalloc(sizeof(struct setkey_parm));
psetkeyparm = kzalloc(sizeof(struct setkey_parm), GFP_KERNEL);
if (!psetkeyparm) {
kfree(pcmd);
res = _FAIL;
Expand Down
30 changes: 15 additions & 15 deletions drivers/staging/r8188eu/core/rtw_mlme_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ unsigned int OnBeacon(struct adapter *padapter, struct recv_frame *precv_frame)
if (!memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) {
if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
/* we should update current network before auth, or some IE is wrong */
pbss = (struct wlan_bssid_ex *)rtw_malloc(sizeof(struct wlan_bssid_ex));
pbss = kmalloc(sizeof(struct wlan_bssid_ex), GFP_ATOMIC);
if (pbss) {
if (collect_bss_info(padapter, precv_frame, pbss) == _SUCCESS) {
update_network(&(pmlmepriv->cur_network.network), pbss, padapter, true);
Expand Down Expand Up @@ -6966,12 +6966,12 @@ void report_survey_event(struct adapter *padapter, struct recv_frame *precv_fram
pmlmeext = &padapter->mlmeextpriv;
pcmdpriv = &padapter->cmdpriv;

pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
if (!pcmd_obj)
return;

cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
if (!pevtcmd) {
kfree(pcmd_obj);
return;
Expand Down Expand Up @@ -7016,12 +7016,12 @@ void report_surveydone_event(struct adapter *padapter)
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct cmd_priv *pcmdpriv = &padapter->cmdpriv;

pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
if (!pcmd_obj)
return;

cmdsz = (sizeof(struct surveydone_event) + sizeof(struct C2HEvent_Header));
pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
if (!pevtcmd) {
kfree(pcmd_obj);
return;
Expand Down Expand Up @@ -7060,12 +7060,12 @@ void report_join_res(struct adapter *padapter, int res)
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
struct cmd_priv *pcmdpriv = &padapter->cmdpriv;

pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
if (!pcmd_obj)
return;

cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
if (!pevtcmd) {
kfree(pcmd_obj);
return;
Expand Down Expand Up @@ -7109,12 +7109,12 @@ void report_del_sta_event(struct adapter *padapter, unsigned char *MacAddr, unsi
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct cmd_priv *pcmdpriv = &padapter->cmdpriv;

pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
if (!pcmd_obj)
return;

cmdsz = (sizeof(struct stadel_event) + sizeof(struct C2HEvent_Header));
pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
if (!pevtcmd) {
kfree(pcmd_obj);
return;
Expand Down Expand Up @@ -7161,12 +7161,12 @@ void report_add_sta_event(struct adapter *padapter, unsigned char *MacAddr, int
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
struct cmd_priv *pcmdpriv = &padapter->cmdpriv;

pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
if (!pcmd_obj)
return;

cmdsz = (sizeof(struct stassoc_event) + sizeof(struct C2HEvent_Header));
pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
if (!pevtcmd) {
kfree(pcmd_obj);
return;
Expand Down Expand Up @@ -7582,11 +7582,11 @@ void survey_timer_hdl(struct adapter *padapter)
pmlmeext->scan_abort = false;/* reset */
}

ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
if (!ph2c)
goto exit_survey_timer_hdl;

psurveyPara = (struct sitesurvey_parm *)rtw_zmalloc(sizeof(struct sitesurvey_parm));
psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
if (!psurveyPara) {
kfree(ph2c);
goto exit_survey_timer_hdl;
Expand Down Expand Up @@ -8158,13 +8158,13 @@ u8 set_tx_beacon_cmd(struct adapter *padapter)
u8 res = _SUCCESS;
int len_diff = 0;

ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
if (!ph2c) {
res = _FAIL;
goto exit;
}

ptxBeacon_parm = (struct Tx_Beacon_param *)rtw_zmalloc(sizeof(struct Tx_Beacon_param));
ptxBeacon_parm = kzalloc(sizeof(struct Tx_Beacon_param), GFP_KERNEL);
if (!ptxBeacon_parm) {
kfree(ph2c);
res = _FAIL;
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/r8188eu/core/rtw_mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ void SetPacketTx(struct adapter *padapter)
kfree(pmp_priv->tx.pallocated_buf);
pmp_priv->tx.write_size = pkt_size;
pmp_priv->tx.buf_size = pkt_size + XMITBUF_ALIGN_SZ;
pmp_priv->tx.pallocated_buf = rtw_zmalloc(pmp_priv->tx.buf_size);
pmp_priv->tx.pallocated_buf = kzalloc(pmp_priv->tx.buf_size, GFP_KERNEL);
if (!pmp_priv->tx.pallocated_buf) {
DBG_88E("%s: malloc(%d) fail!!\n", __func__, pmp_priv->tx.buf_size);
return;
Expand Down
8 changes: 4 additions & 4 deletions drivers/staging/r8188eu/core/rtw_p2p.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf)

DBG_88E("%s\n", __func__);

pdata_attr = rtw_zmalloc(MAX_P2P_IE_LEN);
pdata_attr = kzalloc(MAX_P2P_IE_LEN, GFP_KERNEL);

pstart = pdata_attr;
pcur = pdata_attr;
Expand Down Expand Up @@ -855,7 +855,7 @@ u32 process_assoc_req_p2p_ie(struct wifidirect_info *pwdinfo, u8 *pframe, uint l
/* Check P2P Device Info ATTR */
if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_DEVICE_INFO, NULL, (uint *)&attr_contentlen)) {
DBG_88E("[%s] Got P2P DEVICE INFO Attr!!\n", __func__);
pattr_content = rtw_zmalloc(attr_contentlen);
pattr_content = kzalloc(attr_contentlen, GFP_KERNEL);
pbuf = pattr_content;
if (pattr_content) {
u8 num_of_secdev_type;
Expand Down Expand Up @@ -1697,13 +1697,13 @@ u8 p2p_ps_wk_cmd(struct adapter *padapter, u8 p2p_ps_state, u8 enqueue)
return res;

if (enqueue) {
ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
if (!ph2c) {
res = _FAIL;
goto exit;
}

pdrvextra_cmd_parm = (struct drvextra_cmd_parm *)rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL);
if (!pdrvextra_cmd_parm) {
kfree(ph2c);
res = _FAIL;
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/r8188eu/core/rtw_wlan_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
return true;
}

bssid = (struct wlan_bssid_ex *)rtw_zmalloc(sizeof(struct wlan_bssid_ex));
bssid = kzalloc(sizeof(struct wlan_bssid_ex), GFP_ATOMIC);
if (!bssid)
return _FAIL;

Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/r8188eu/core/rtw_xmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ void rtw_alloc_hwxmits(struct adapter *padapter)

pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;

pxmitpriv->hwxmits = (struct hw_xmit *)rtw_zmalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry);
pxmitpriv->hwxmits = kzalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry, GFP_KERNEL);

hwxmits = pxmitpriv->hwxmits;

Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/r8188eu/hal/rtl8188e_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ static void SetFwRsvdPagePkt(struct adapter *adapt, bool bDLFinished)
struct rsvdpage_loc RsvdPageLoc;

DBG_88E("%s\n", __func__);
ReservedPagePacket = (u8 *)rtw_zmalloc(1000);
ReservedPagePacket = kzalloc(1000, GFP_KERNEL);
if (!ReservedPagePacket) {
DBG_88E("%s: alloc ReservedPagePacket fail!\n", __func__);
return;
Expand Down
8 changes: 4 additions & 4 deletions drivers/staging/r8188eu/hal/rtl8188e_hal_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
u16 efuse_utilized = 0;
u8 u1temp = 0;

efuseTbl = (u8 *)rtw_zmalloc(EFUSE_MAP_LEN_88E);
efuseTbl = kzalloc(EFUSE_MAP_LEN_88E, GFP_KERNEL);
if (!efuseTbl) {
DBG_88E("%s: alloc efuseTbl fail!\n", __func__);
goto exit;
}

eFuseWord = (u16 **)rtw_malloc2d(EFUSE_MAX_SECTION_88E, EFUSE_MAX_WORD_UNIT, sizeof(u16));
eFuseWord = rtw_malloc2d(EFUSE_MAX_SECTION_88E, EFUSE_MAX_WORD_UNIT, sizeof(u16));
if (!eFuseWord) {
DBG_88E("%s: alloc eFuseWord fail!\n", __func__);
goto exit;
Expand Down Expand Up @@ -790,13 +790,13 @@ static void Hal_EfuseReadEFuse88E(struct adapter *Adapter,
goto exit;
}

efuseTbl = (u8 *)rtw_zmalloc(EFUSE_MAP_LEN_88E);
efuseTbl = kzalloc(EFUSE_MAP_LEN_88E, GFP_KERNEL);
if (!efuseTbl) {
DBG_88E("%s: alloc efuseTbl fail!\n", __func__);
goto exit;
}

eFuseWord = (u16 **)rtw_malloc2d(EFUSE_MAX_SECTION_88E, EFUSE_MAX_WORD_UNIT, sizeof(u16));
eFuseWord = rtw_malloc2d(EFUSE_MAX_SECTION_88E, EFUSE_MAX_WORD_UNIT, sizeof(u16));
if (!eFuseWord) {
DBG_88E("%s: alloc eFuseWord fail!\n", __func__);
goto exit;
Expand Down
3 changes: 2 additions & 1 deletion drivers/staging/r8188eu/hal/rtl8188eu_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ int rtl8188eu_init_recv_priv(struct adapter *padapter)
/* init recv_buf */
_rtw_init_queue(&precvpriv->free_recv_buf_queue);

precvpriv->pallocated_recv_buf = rtw_zmalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4);
precvpriv->pallocated_recv_buf = kzalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4,
GFP_KERNEL);
if (!precvpriv->pallocated_recv_buf) {
res = _FAIL;
goto exit;
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/r8188eu/hal/usb_halinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ void rtl8188eu_set_hal_ops(struct adapter *adapt)
{
struct hal_ops *halfunc = &adapt->HalFunc;

adapt->HalData = rtw_zmalloc(sizeof(struct hal_data_8188e));
adapt->HalData = kzalloc(sizeof(struct hal_data_8188e), GFP_KERNEL);
if (!adapt->HalData)
DBG_88E("cant not alloc memory for HAL DATA\n");
adapt->hal_data_sz = sizeof(struct hal_data_8188e);
Expand Down
6 changes: 0 additions & 6 deletions drivers/staging/r8188eu/include/osdep_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,9 @@ extern unsigned char RSN_TKIP_CIPHER[4];
u8 *_rtw_vmalloc(u32 sz);
u8 *_rtw_zvmalloc(u32 sz);
void _rtw_vmfree(u8 *pbuf, u32 sz);
u8 *_rtw_zmalloc(u32 sz);
u8 *_rtw_malloc(u32 sz);
void _rtw_mfree(u8 *pbuf, u32 sz);
#define rtw_vmalloc(sz) _rtw_vmalloc((sz))
#define rtw_zvmalloc(sz) _rtw_zvmalloc((sz))
#define rtw_vmfree(pbuf, sz) _rtw_vmfree((pbuf), (sz))
#define rtw_malloc(sz) _rtw_malloc((sz))
#define rtw_zmalloc(sz) _rtw_zmalloc((sz))
#define rtw_mfree(pbuf, sz) _rtw_mfree((pbuf), (sz))

void *rtw_malloc2d(int h, int w, int size);

Expand Down
Loading

0 comments on commit 79f712e

Please sign in to comment.