From 79f712ea994de30b3887a45e9ca42fd47b840b62 Mon Sep 17 00:00:00 2001 From: Larry Finger Date: Thu, 5 Aug 2021 13:37:13 -0500 Subject: staging: r8188eu: Remove wrappers for kalloc() and kzalloc() 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 Link: https://lore.kernel.org/r/20210805183717.23007-2-Larry.Finger@lwfinger.net Signed-off-by: Greg Kroah-Hartman --- drivers/staging/r8188eu/os_dep/ioctl_linux.c | 66 ++++++++++++-------------- drivers/staging/r8188eu/os_dep/mlme_linux.c | 3 +- drivers/staging/r8188eu/os_dep/osdep_service.c | 28 ++--------- drivers/staging/r8188eu/os_dep/usb_intf.c | 4 +- drivers/staging/r8188eu/os_dep/xmit_linux.c | 2 +- 5 files changed, 38 insertions(+), 65 deletions(-) (limited to 'drivers/staging/r8188eu/os_dep') diff --git a/drivers/staging/r8188eu/os_dep/ioctl_linux.c b/drivers/staging/r8188eu/os_dep/ioctl_linux.c index 8ba2b81e32b8..5f4355cb03e7 100644 --- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c +++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c @@ -522,7 +522,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, if (wep_key_len > 0) { wep_key_len = wep_key_len <= 5 ? 5 : 13; wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial); - pwep = (struct ndis_802_11_wep *)rtw_malloc(wep_total_len); + pwep = kmalloc(wep_total_len, GFP_KERNEL); if (!pwep) { RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, (" wpa_set_encryption: pwep allocate fail !!!\n")); goto exit; @@ -642,7 +642,7 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie } if (ielen) { - buf = rtw_zmalloc(ielen); + buf = kzalloc(ielen, GFP_KERNEL); if (!buf) { ret = -ENOMEM; goto exit; @@ -2109,11 +2109,9 @@ static int rtw_wx_set_enc_ext(struct net_device *dev, int ret = 0; param_len = sizeof(struct ieee_param) + pext->key_len; - param = (struct ieee_param *)rtw_malloc(param_len); + param = kzalloc(param_len, GFP_KERNEL); if (!param) - return -1; - - memset(param, 0, param_len); + return -ENOMEM; param->cmd = IEEE_CMD_SET_ENCRYPTION; memset(param->sta_addr, 0xff, ETH_ALEN); @@ -2194,8 +2192,8 @@ static int rtw_wx_read32(struct net_device *dev, padapter = (struct adapter *)rtw_netdev_priv(dev); p = &wrqu->data; len = p->length; - ptmp = (u8 *)rtw_malloc(len); - if (NULL == ptmp) + ptmp = kmalloc(len, GFP_KERNEL); + if (!ptmp) return -ENOMEM; if (copy_from_user(ptmp, p->pointer, len)) { @@ -2464,7 +2462,7 @@ static int rtw_mp_ioctl_hdl(struct net_device *dev, struct iw_request_info *info pparmbuf = NULL; bset = (u8)(p->flags & 0xFFFF); len = p->length; - pparmbuf = (u8 *)rtw_malloc(len); + pparmbuf = kmalloc(len, GFP_KERNEL); if (!pparmbuf) { ret = -ENOMEM; goto _rtw_mp_ioctl_hdl_exit; @@ -4674,7 +4672,7 @@ static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p) goto out; } - param = (struct ieee_param *)rtw_malloc(p->length); + param = kmalloc(p->length, GFP_KERNEL); if (!param) { ret = -ENOMEM; goto out; @@ -4728,13 +4726,13 @@ static u8 set_pairwise_key(struct adapter *padapter, struct sta_info *psta) struct cmd_priv *pcmdpriv = &padapter->cmdpriv; u8 res = _SUCCESS; - ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj)); + ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); if (!ph2c) { res = _FAIL; goto exit; } - psetstakey_para = (struct set_stakey_parm *)rtw_zmalloc(sizeof(struct set_stakey_parm)); + psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_KERNEL); if (!psetstakey_para) { kfree(ph2c); res = _FAIL; @@ -4766,12 +4764,12 @@ static int set_group_key(struct adapter *padapter, u8 *key, u8 alg, int keyid) DBG_88E("%s\n", __func__); - pcmd = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj)); + pcmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); if (!pcmd) { res = _FAIL; 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; @@ -4887,14 +4885,11 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, if (wep_key_len > 0) { wep_key_len = wep_key_len <= 5 ? 5 : 13; wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial); - pwep = (struct ndis_802_11_wep *)rtw_malloc(wep_total_len); + pwep = kzalloc(wep_total_len, GFP_KERNEL); if (!pwep) { - DBG_88E(" r871x_set_encryption: pwep allocate fail !!!\n"); + ret = -ENOMEM; goto exit; } - - memset(pwep, 0, wep_total_len); - pwep->KeyLength = wep_key_len; pwep->Length = wep_total_len; } @@ -5315,7 +5310,7 @@ static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, } if (ie_len > 0) { - pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len); + pmlmepriv->wps_beacon_ie = kmalloc(ie_len, GFP_KERNEL); pmlmepriv->wps_beacon_ie_len = ie_len; if (!pmlmepriv->wps_beacon_ie) { DBG_88E("%s()-%d: rtw_malloc() ERROR!\n", __func__, __LINE__); @@ -5352,7 +5347,7 @@ static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *par } if (ie_len > 0) { - pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len); + pmlmepriv->wps_probe_resp_ie = kmalloc(ie_len, GFP_KERNEL); pmlmepriv->wps_probe_resp_ie_len = ie_len; if (!pmlmepriv->wps_probe_resp_ie) { DBG_88E("%s()-%d: rtw_malloc() ERROR!\n", __func__, __LINE__); @@ -5384,11 +5379,11 @@ static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *par } if (ie_len > 0) { - pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len); + pmlmepriv->wps_assoc_resp_ie = kmalloc(ie_len, GFP_KERNEL); pmlmepriv->wps_assoc_resp_ie_len = ie_len; if (!pmlmepriv->wps_assoc_resp_ie) { DBG_88E("%s()-%d: rtw_malloc() ERROR!\n", __func__, __LINE__); - return -EINVAL; + return -ENOMEM; } memcpy(pmlmepriv->wps_assoc_resp_ie, param->u.bcn_ie.buf, ie_len); @@ -5491,7 +5486,7 @@ static int rtw_hostapd_ioctl(struct net_device *dev, struct iw_point *p) goto out; } - param = (struct ieee_param *)rtw_malloc(p->length); + param = kmalloc(p->length, GFP_KERNEL); if (!param) { ret = -ENOMEM; goto out; @@ -5600,9 +5595,8 @@ static int rtw_wx_set_priv(struct net_device *dev, kfree(pmlmepriv->wps_probe_req_ie); pmlmepriv->wps_probe_req_ie = NULL; - pmlmepriv->wps_probe_req_ie = rtw_malloc(cp_sz); + pmlmepriv->wps_probe_req_ie = kmalloc(cp_sz, GFP_KERNEL); if (!pmlmepriv->wps_probe_req_ie) { - pr_info("%s()-%d: rtw_malloc() ERROR!\n", __func__, __LINE__); ret = -EINVAL; goto FREE_EXT; } @@ -5674,12 +5668,12 @@ static int rtw_mp_efuse_get(struct net_device *dev, pEfuseHal = &haldata->EfuseHal; err = 0; - data = _rtw_zmalloc(EFUSE_BT_MAX_MAP_LEN); + data = kzalloc(EFUSE_BT_MAX_MAP_LEN, GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; } - rawdata = _rtw_zmalloc(EFUSE_BT_MAX_MAP_LEN); + rawdata = kzalloc(EFUSE_BT_MAX_MAP_LEN, GFP_KERNEL); if (!rawdata) { err = -ENOMEM; goto exit; @@ -5989,22 +5983,22 @@ static int rtw_mp_efuse_set(struct net_device *dev, haldata = GET_HAL_DATA(padapter); pEfuseHal = &haldata->EfuseHal; err = 0; - setdata = _rtw_zmalloc(1024); + setdata = kzalloc(1024, GFP_KERNEL); if (!setdata) { err = -ENOMEM; goto exit; } - ShadowMapBT = _rtw_malloc(EFUSE_BT_MAX_MAP_LEN); + ShadowMapBT = kmalloc(EFUSE_BT_MAX_MAP_LEN, GFP_KERNEL); if (!ShadowMapBT) { err = -ENOMEM; goto exit; } - ShadowMapWiFi = _rtw_malloc(EFUSE_MAP_SIZE); + ShadowMapWiFi = kmalloc(EFUSE_MAP_SIZE, GFP_KERNEL); if (!ShadowMapWiFi) { err = -ENOMEM; goto exit; } - setrawdata = _rtw_malloc(EFUSE_MAX_SIZE); + setrawdata = kmalloc(EFUSE_MAX_SIZE, GFP_KERNEL); if (!setrawdata) { err = -ENOMEM; goto exit; @@ -7486,7 +7480,7 @@ static int rtw_test( DBG_88E("+%s\n", __func__); len = wrqu->data.length; - pbuf = (u8 *)rtw_zmalloc(len); + pbuf = kzalloc(len, GFP_KERNEL); if (!pbuf) { DBG_88E("%s: no memory!\n", __func__); return -ENOMEM; @@ -7832,7 +7826,7 @@ static int rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_ input_len = wdata.data.length; if (input_len == 0) return -EFAULT; - input = rtw_zmalloc(input_len); + input = kzalloc(input_len, GFP_KERNEL); if (NULL == input) return -ENOMEM; if (copy_from_user(input, wdata.data.pointer, input_len)) { @@ -7895,7 +7889,7 @@ static int rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_ k = j; } - buffer = rtw_zmalloc(4096); + buffer = kzalloc(4096, GFP_KERNEL); if (NULL == buffer) { err = -ENOMEM; goto exit; @@ -8044,7 +8038,7 @@ static int rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_ else n = wdata.data.length; - output = rtw_zmalloc(4096); + output = kzalloc(4096, GFP_KERNEL); if (NULL == output) { err = -ENOMEM; goto exit; diff --git a/drivers/staging/r8188eu/os_dep/mlme_linux.c b/drivers/staging/r8188eu/os_dep/mlme_linux.c index 766b346afbb8..0855b218f7b1 100644 --- a/drivers/staging/r8188eu/os_dep/mlme_linux.c +++ b/drivers/staging/r8188eu/os_dep/mlme_linux.c @@ -119,10 +119,9 @@ void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie) if (authmode == _WPA_IE_ID_) { RT_TRACE(_module_mlme_osdep_c_, _drv_info_, ("rtw_report_sec_ie, authmode=%d\n", authmode)); - buff = rtw_malloc(IW_CUSTOM_MAX); + buff = kzalloc(IW_CUSTOM_MAX, GFP_KERNEL); if (!buff) return; - memset(buff, 0, IW_CUSTOM_MAX); p = buff; p += sprintf(p, "ASSOCINFO(ReqIEs ="); len = sec_ie[1]+2; diff --git a/drivers/staging/r8188eu/os_dep/osdep_service.c b/drivers/staging/r8188eu/os_dep/osdep_service.c index 250d499e4d4a..9cf9f272cccb 100644 --- a/drivers/staging/r8188eu/os_dep/osdep_service.c +++ b/drivers/staging/r8188eu/os_dep/osdep_service.c @@ -58,32 +58,13 @@ inline void _rtw_vmfree(u8 *pbuf, u32 sz) vfree(pbuf); } -u8 *_rtw_malloc(u32 sz) -{ - u8 *pbuf = NULL; - - pbuf = kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); - return pbuf; -} - -u8 *_rtw_zmalloc(u32 sz) -{ - u8 *pbuf = _rtw_malloc(sz); - - if (pbuf) - memset(pbuf, 0, sz); - return pbuf; -} - void *rtw_malloc2d(int h, int w, int size) { int j; - void **a = (void **)rtw_zmalloc(h*sizeof(void *) + h*w*size); - if (!a) { - pr_info("%s: alloc memory fail!\n", __func__); + void **a = kzalloc(h * sizeof(void *) + h * w * size, GFP_KERNEL); + if (!a) return NULL; - } for (j = 0; j < h; j++) a[j] = ((char *)(a+h)) + j*w*size; @@ -331,7 +312,7 @@ void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len) goto keep_ori; /* duplicate src */ - dup = rtw_malloc(src_len); + dup = kmalloc(src_len, GFP_ATOMIC); if (dup) { dup_len = src_len; memcpy(dup, src, dup_len); @@ -423,8 +404,7 @@ struct rtw_cbuf *rtw_cbuf_alloc(u32 size) { struct rtw_cbuf *cbuf; - cbuf = (struct rtw_cbuf *)rtw_malloc(sizeof(*cbuf) + - sizeof(void *)*size); + cbuf = kmalloc(sizeof(*cbuf) + sizeof(void *)*size, GFP_KERNEL); if (cbuf) { cbuf->write = 0; diff --git a/drivers/staging/r8188eu/os_dep/usb_intf.c b/drivers/staging/r8188eu/os_dep/usb_intf.c index fffc2c0d9efb..f3321a6653fc 100644 --- a/drivers/staging/r8188eu/os_dep/usb_intf.c +++ b/drivers/staging/r8188eu/os_dep/usb_intf.c @@ -118,7 +118,7 @@ static u8 rtw_init_intf_priv(struct dvobj_priv *dvobj) _rtw_mutex_init(&dvobj->usb_vendor_req_mutex); - dvobj->usb_alloc_vendor_req_buf = rtw_zmalloc(MAX_USB_IO_CTL_SIZE); + dvobj->usb_alloc_vendor_req_buf = kzalloc(MAX_USB_IO_CTL_SIZE, GFP_KERNEL); if (!dvobj->usb_alloc_vendor_req_buf) { DBG_88E("alloc usb_vendor_req_buf failed... /n"); rst = _FAIL; @@ -150,7 +150,7 @@ static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf) struct usb_endpoint_descriptor *pendp_desc; struct usb_device *pusbd; - pdvobjpriv = (struct dvobj_priv *)rtw_zmalloc(sizeof(*pdvobjpriv)); + pdvobjpriv = kzalloc(sizeof(*pdvobjpriv), GFP_KERNEL); if (!pdvobjpriv) goto exit; diff --git a/drivers/staging/r8188eu/os_dep/xmit_linux.c b/drivers/staging/r8188eu/os_dep/xmit_linux.c index 421328173984..df9bdbff91ac 100644 --- a/drivers/staging/r8188eu/os_dep/xmit_linux.c +++ b/drivers/staging/r8188eu/os_dep/xmit_linux.c @@ -76,7 +76,7 @@ int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitb { int i; - pxmitbuf->pallocated_buf = rtw_zmalloc(alloc_sz); + pxmitbuf->pallocated_buf = kzalloc(alloc_sz, GFP_KERNEL); if (!pxmitbuf->pallocated_buf) return _FAIL; -- cgit