From 2a467a7923a5ed19b090b41f43842bbf6bdedd07 Mon Sep 17 00:00:00 2001 From: Phillip Potter Date: Thu, 19 Aug 2021 00:48:50 +0100 Subject: [PATCH] convert all rtw_zvmalloc calls to vzalloc calls Convert all rtw_zvmalloc calls within the driver to use the existing kernel vzalloc function, which has the same semantics. Also rewrite the two places where it is mentioned in comments to say vzalloc, and remove the redundant cast to struct adapter * in ./os_dep/usb_intf.c as vzalloc returns void *. The reason for the conversion is that rtw_zvmalloc is just a preprocessor definition for _rtw_zvmalloc which itself is just an inline wrapper around vmalloc which then zeroes the memory out. As vzalloc does the same thing via usage of __GFP_ZERO, this code is redundant and can subsequently be removed. Link: https://lore.kernel.org/r/20210818234853.208448-5-phil@philpotter.co.uk --- core/mesh/rtw_mesh.c | 2 +- core/rtw_mlme.c | 4 ++-- core/rtw_mlme_ext.c | 2 +- core/rtw_mp.c | 2 +- core/rtw_recv.c | 4 ++-- core/rtw_rf.c | 2 +- core/rtw_sta_mgt.c | 2 +- core/rtw_xmit.c | 10 +++++----- hal/hal_com.c | 6 +++--- hal/hal_com_phycfg.c | 14 +++++++------- hal/hal_halmac.c | 2 +- hal/hal_intf.c | 2 +- hal/phydm/phydm_interface.c | 4 ++-- os_dep/linux/os_intfs.c | 4 ++-- os_dep/linux/usb_intf.c | 2 +- os_dep/osdep_service.c | 2 +- 16 files changed, 32 insertions(+), 32 deletions(-) diff --git a/core/mesh/rtw_mesh.c b/core/mesh/rtw_mesh.c index 1d51b54..1c12a6c 100644 --- a/core/mesh/rtw_mesh.c +++ b/core/mesh/rtw_mesh.c @@ -1077,7 +1077,7 @@ void dump_mesh_networks(void *sel, _adapter *adapter) u8 mesh_network_cnt = 0; int i; - mesh_networks = rtw_zvmalloc(mlme->max_bss_cnt * sizeof(struct wlan_network *)); + mesh_networks = vzalloc(mlme->max_bss_cnt * sizeof(struct wlan_network *)); if (!mesh_networks) return; diff --git a/core/rtw_mlme.c b/core/rtw_mlme.c index 66e7b6d..5a1f552 100644 --- a/core/rtw_mlme.c +++ b/core/rtw_mlme.c @@ -47,7 +47,7 @@ sint _rtw_init_mlme_priv(_adapter *padapter) sint res = _SUCCESS; - /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */ + /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */ /* memset((u8 *)pmlmepriv, 0, sizeof(struct mlme_priv)); */ @@ -82,7 +82,7 @@ sint _rtw_init_mlme_priv(_adapter *padapter) pmlmepriv->max_bss_cnt = MAX_BSS_CNT + MAX_BSS_CNT; - pbuf = rtw_zvmalloc(pmlmepriv->max_bss_cnt * (sizeof(struct wlan_network))); + pbuf = vzalloc(pmlmepriv->max_bss_cnt * (sizeof(struct wlan_network))); if (pbuf == NULL) { res = _FAIL; diff --git a/core/rtw_mlme_ext.c b/core/rtw_mlme_ext.c index 4edb354..eee4dfb 100644 --- a/core/rtw_mlme_ext.c +++ b/core/rtw_mlme_ext.c @@ -1130,7 +1130,7 @@ int init_mlme_ext_priv(_adapter *padapter) struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); - /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */ + /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */ /* memset((u8 *)pmlmeext, 0, sizeof(struct mlme_ext_priv)); */ pmlmeext->padapter = padapter; diff --git a/core/rtw_mp.c b/core/rtw_mp.c index 9175f6a..2309e0c 100644 --- a/core/rtw_mp.c +++ b/core/rtw_mp.c @@ -2505,7 +2505,7 @@ void _rtw_mp_xmit_priv(struct xmit_priv *pxmitpriv) /* Init xmit extension buff */ _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue); - pxmitpriv->pallocated_xmit_extbuf = rtw_zvmalloc(num_xmit_extbuf * sizeof(struct xmit_buf) + 4); + pxmitpriv->pallocated_xmit_extbuf = vzalloc(num_xmit_extbuf * sizeof(struct xmit_buf) + 4); if (pxmitpriv->pallocated_xmit_extbuf == NULL) { res = _FAIL; diff --git a/core/rtw_recv.c b/core/rtw_recv.c index 71f477b..aa26039 100644 --- a/core/rtw_recv.c +++ b/core/rtw_recv.c @@ -80,7 +80,7 @@ sint _rtw_init_recv_priv(struct recv_priv *precvpriv, _adapter *padapter) sint res = _SUCCESS; - /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */ + /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */ /* memset((unsigned char *)precvpriv, 0, sizeof (struct recv_priv)); */ _rtw_spinlock_init(&precvpriv->lock); @@ -110,7 +110,7 @@ sint _rtw_init_recv_priv(struct recv_priv *precvpriv, _adapter *padapter) rtw_os_recv_resource_init(precvpriv, padapter); - precvpriv->pallocated_frame_buf = rtw_zvmalloc(NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ); + precvpriv->pallocated_frame_buf = vzalloc(NR_RECVFRAME * sizeof(union recv_frame) + RXFRAME_ALIGN_SZ); if (precvpriv->pallocated_frame_buf == NULL) { res = _FAIL; diff --git a/core/rtw_rf.c b/core/rtw_rf.c index b74e2e5..d8667bc 100644 --- a/core/rtw_rf.c +++ b/core/rtw_rf.c @@ -1056,7 +1056,7 @@ void rtw_txpwr_lmt_add_with_nlen(struct rf_ctl_t *rfctl, const char *regd_name, } /* alloc new one */ - ent = (struct txpwr_lmt_ent *)rtw_zvmalloc(sizeof(struct txpwr_lmt_ent) + nlen + 1); + ent = (struct txpwr_lmt_ent *)vzalloc(sizeof(struct txpwr_lmt_ent) + nlen + 1); if (!ent) goto release_lock; diff --git a/core/rtw_sta_mgt.c b/core/rtw_sta_mgt.c index c26d50f..86873d0 100644 --- a/core/rtw_sta_mgt.c +++ b/core/rtw_sta_mgt.c @@ -237,7 +237,7 @@ u32 _rtw_init_sta_priv(struct sta_priv *pstapriv) pstapriv->padapter = adapter; - pstapriv->pallocated_stainfo_buf = rtw_zvmalloc(sizeof(struct sta_info) * NUM_STA + 4); + pstapriv->pallocated_stainfo_buf = vzalloc(sizeof(struct sta_info) * NUM_STA + 4); if (!pstapriv->pallocated_stainfo_buf) goto exit; diff --git a/core/rtw_xmit.c b/core/rtw_xmit.c index 9c9f569..5212fdf 100644 --- a/core/rtw_xmit.c +++ b/core/rtw_xmit.c @@ -71,7 +71,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, _adapter *padapter) sint res = _SUCCESS; - /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */ + /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */ /* memset((unsigned char *)pxmitpriv, 0, sizeof(struct xmit_priv)); */ _rtw_spinlock_init(&pxmitpriv->lock); @@ -104,7 +104,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, _adapter *padapter) Please also apply free_txobj to link_up all the xmit_frames... */ - pxmitpriv->pallocated_frame_buf = rtw_zvmalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4); + pxmitpriv->pallocated_frame_buf = vzalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4); if (pxmitpriv->pallocated_frame_buf == NULL) { pxmitpriv->pxmit_frame_buf = NULL; @@ -142,7 +142,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, _adapter *padapter) _rtw_init_queue(&pxmitpriv->free_xmitbuf_queue); _rtw_init_queue(&pxmitpriv->pending_xmitbuf_queue); - pxmitpriv->pallocated_xmitbuf = rtw_zvmalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4); + pxmitpriv->pallocated_xmitbuf = vzalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4); if (pxmitpriv->pallocated_xmitbuf == NULL) { res = _FAIL; @@ -194,7 +194,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, _adapter *padapter) /* init xframe_ext queue, the same count as extbuf */ _rtw_init_queue(&pxmitpriv->free_xframe_ext_queue); - pxmitpriv->xframe_ext_alloc_addr = rtw_zvmalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_frame) + 4); + pxmitpriv->xframe_ext_alloc_addr = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_frame) + 4); if (pxmitpriv->xframe_ext_alloc_addr == NULL) { pxmitpriv->xframe_ext = NULL; @@ -226,7 +226,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, _adapter *padapter) /* Init xmit extension buff */ _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue); - pxmitpriv->pallocated_xmit_extbuf = rtw_zvmalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_buf) + 4); + pxmitpriv->pallocated_xmit_extbuf = vzalloc(NR_XMIT_EXTBUFF * sizeof(struct xmit_buf) + 4); if (pxmitpriv->pallocated_xmit_extbuf == NULL) { res = _FAIL; diff --git a/hal/hal_com.c b/hal/hal_com.c index d0cb0b3..505cc8c 100644 --- a/hal/hal_com.c +++ b/hal/hal_com.c @@ -4696,7 +4696,7 @@ void rtw_dump_rsvd_page(void *sel, _adapter *adapter, u8 page_offset, u8 page_nu rtw_hal_get_def_var(adapter, HAL_DEF_TX_PAGE_SIZE, &page_size); if (page_size) { buf_size = page_size * page_num; - buffer = rtw_zvmalloc(buf_size); + buffer = vzalloc(buf_size); if (buffer) { rtw_hal_get_rsvd_page(adapter, page_offset, page_num, buffer, buf_size); @@ -4729,7 +4729,7 @@ void rtw_dump_fifo(void *sel, _adapter *adapter, u8 fifo_sel, u32 fifo_addr, u32 if (fifo_size) { buff_size = RND4(fifo_size); - buffer = rtw_zvmalloc(buff_size); + buffer = vzalloc(buff_size); if (buffer == NULL) buff_size = 0; } @@ -5190,7 +5190,7 @@ static void rtw_hal_get_aoac_rpt(_adapter *adapter) rtw_hal_get_def_var(adapter, HAL_DEF_TX_PAGE_SIZE, &page_size); buf_size = page_size * page_number; - buffer = rtw_zvmalloc(buf_size); + buffer = vzalloc(buf_size); if (buffer == NULL) { RTW_ERR("%s buffer allocate failed size(%d)\n", diff --git a/hal/hal_com_phycfg.c b/hal/hal_com_phycfg.c index 6424101..98a8b76 100644 --- a/hal/hal_com_phycfg.c +++ b/hal/hal_com_phycfg.c @@ -4092,7 +4092,7 @@ phy_ConfigMACWithParaFile( rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN); if (rlen > 0) { rtStatus = _SUCCESS; - pHalData->mac_reg = rtw_zvmalloc(rlen); + pHalData->mac_reg = vzalloc(rlen); if (pHalData->mac_reg) { _rtw_memcpy(pHalData->mac_reg, pHalData->para_file_buf, rlen); pHalData->mac_reg_len = rlen; @@ -4171,7 +4171,7 @@ phy_ConfigBBWithParaFile( rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN); if (rlen > 0) { rtStatus = _SUCCESS; - pBuf = rtw_zvmalloc(rlen); + pBuf = vzalloc(rlen); if (pBuf) { _rtw_memcpy(pBuf, pHalData->para_file_buf, rlen); *pBufLen = rlen; @@ -4477,7 +4477,7 @@ phy_ConfigBBWithPgParaFile( rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN); if (rlen > 0) { rtStatus = _SUCCESS; - pHalData->bb_phy_reg_pg = rtw_zvmalloc(rlen); + pHalData->bb_phy_reg_pg = vzalloc(rlen); if (pHalData->bb_phy_reg_pg) { _rtw_memcpy(pHalData->bb_phy_reg_pg, pHalData->para_file_buf, rlen); pHalData->bb_phy_reg_pg_len = rlen; @@ -4526,7 +4526,7 @@ phy_ConfigBBWithMpParaFile( rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN); if (rlen > 0) { rtStatus = _SUCCESS; - pHalData->bb_phy_reg_mp = rtw_zvmalloc(rlen); + pHalData->bb_phy_reg_mp = vzalloc(rlen); if (pHalData->bb_phy_reg_mp) { _rtw_memcpy(pHalData->bb_phy_reg_mp, pHalData->para_file_buf, rlen); pHalData->bb_phy_reg_mp_len = rlen; @@ -4630,7 +4630,7 @@ PHY_ConfigRFWithParaFile( rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN); if (rlen > 0) { rtStatus = _SUCCESS; - pBuf = rtw_zvmalloc(rlen); + pBuf = vzalloc(rlen); if (pBuf) { _rtw_memcpy(pBuf, pHalData->para_file_buf, rlen); *pBufLen = rlen; @@ -4829,7 +4829,7 @@ PHY_ConfigRFWithTxPwrTrackParaFile( rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN); if (rlen > 0) { rtStatus = _SUCCESS; - pHalData->rf_tx_pwr_track = rtw_zvmalloc(rlen); + pHalData->rf_tx_pwr_track = vzalloc(rlen); if (pHalData->rf_tx_pwr_track) { _rtw_memcpy(pHalData->rf_tx_pwr_track, pHalData->para_file_buf, rlen); pHalData->rf_tx_pwr_track_len = rlen; @@ -5328,7 +5328,7 @@ PHY_ConfigRFWithPowerLimitTableParaFile( rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN); if (rlen > 0) { rtStatus = _SUCCESS; - pHalData->rf_tx_pwr_lmt = rtw_zvmalloc(rlen); + pHalData->rf_tx_pwr_lmt = vzalloc(rlen); if (pHalData->rf_tx_pwr_lmt) { _rtw_memcpy(pHalData->rf_tx_pwr_lmt, pHalData->para_file_buf, rlen); pHalData->rf_tx_pwr_lmt_len = rlen; diff --git a/hal/hal_halmac.c b/hal/hal_halmac.c index 907e487..cb6a1a6 100644 --- a/hal/hal_halmac.c +++ b/hal/hal_halmac.c @@ -4388,7 +4388,7 @@ int rtw_halmac_dump_fifo(struct dvobj_priv *d, u8 fifo_sel, u32 addr, u32 size, fifo_size = api->halmac_get_fifo_size(mac, halmac_fifo_sel); if (fifo_size) - pfifo_map = rtw_zvmalloc(fifo_size); + pfifo_map = vzalloc(fifo_size); if (pfifo_map == NULL) return -1; mem_created = _TRUE; diff --git a/hal/hal_intf.c b/hal/hal_intf.c index bdfeb4e..9f52d0c 100644 --- a/hal/hal_intf.c +++ b/hal/hal_intf.c @@ -147,7 +147,7 @@ u8 rtw_hal_data_init(_adapter *padapter) { if (is_primary_adapter(padapter)) { padapter->hal_data_sz = sizeof(HAL_DATA_TYPE); - padapter->HalData = rtw_zvmalloc(padapter->hal_data_sz); + padapter->HalData = vzalloc(padapter->hal_data_sz); if (padapter->HalData == NULL) { RTW_INFO("cant not alloc memory for HAL DATA\n"); return _FAIL; diff --git a/hal/phydm/phydm_interface.c b/hal/phydm/phydm_interface.c index 6cdb3f6..028c4b5 100644 --- a/hal/phydm/phydm_interface.c +++ b/hal/phydm/phydm_interface.c @@ -370,12 +370,12 @@ void odm_allocate_memory(struct dm_struct *dm, void **ptr, u32 length) #elif (DM_ODM_SUPPORT_TYPE & ODM_CE) && defined(DM_ODM_CE_MAC80211_V2) *ptr = kmalloc(length, GFP_ATOMIC); #elif (DM_ODM_SUPPORT_TYPE & ODM_CE) - *ptr = rtw_zvmalloc(length); + *ptr = vzalloc(length); #elif (DM_ODM_SUPPORT_TYPE & ODM_WIN) void *adapter = dm->adapter; PlatformAllocateMemory(adapter, ptr, length); #elif (DM_ODM_SUPPORT_TYPE & ODM_IOT) - *ptr = rtw_zvmalloc(length); + *ptr = vzalloc(length); #endif } diff --git a/os_dep/linux/os_intfs.c b/os_dep/linux/os_intfs.c index 3632c4d..fee8204 100644 --- a/os_dep/linux/os_intfs.c +++ b/os_dep/linux/os_intfs.c @@ -2396,7 +2396,7 @@ u8 rtw_init_drv_sw(_adapter *padapter) /* add for CONFIG_IEEE80211W, none 11w also can use */ _rtw_spinlock_init(&padapter->security_key_mutex); - /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */ + /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */ /* memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv)); */ if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) { @@ -2805,7 +2805,7 @@ _adapter *rtw_drv_add_vir_if(_adapter *primary_padapter, u8 mac[ETH_ALEN]; /****** init adapter ******/ - padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter)); + padapter = (_adapter *)vzalloc(sizeof(*padapter)); if (padapter == NULL) goto exit; diff --git a/os_dep/linux/usb_intf.c b/os_dep/linux/usb_intf.c index 37b6cee..87b9d56 100644 --- a/os_dep/linux/usb_intf.c +++ b/os_dep/linux/usb_intf.c @@ -1270,7 +1270,7 @@ _adapter *rtw_usb_primary_adapter_init(struct dvobj_priv *dvobj, _adapter *padapter = NULL; int status = _FAIL; - padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter)); + padapter = (_adapter *)vzalloc(sizeof(*padapter)); if (padapter == NULL) goto exit; diff --git a/os_dep/osdep_service.c b/os_dep/osdep_service.c index 1e23cc0..d5e9c87 100644 --- a/os_dep/osdep_service.c +++ b/os_dep/osdep_service.c @@ -2028,7 +2028,7 @@ struct net_device *rtw_alloc_etherdev(int sizeof_priv) pnpi = netdev_priv(pnetdev); - pnpi->priv = rtw_zvmalloc(sizeof_priv); + pnpi->priv = vzalloc(sizeof_priv); if (!pnpi->priv) { free_netdev(pnetdev); pnetdev = NULL;