staging: r8188eu: replace rtw_malloc() with it's definition
PATCH 1/1 staging: r8188eu: replace rtw_malloc() with it's definition
rtw_malloc prevents the use of kmemdup/kzalloc and others.
--- drivers/staging/rtl8188eu/core/rtw_ap.c | 4 ++-- drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 2 +- .../staging/rtl8188eu/include/osdep_service.h | 3 --- drivers/staging/rtl8188eu/os_dep/ioctl_linux.c | 18 +++++++++--------- drivers/staging/rtl8188eu/os_dep/mlme_linux.c | 2 +- .../staging/rtl8188eu/os_dep/osdep_service.c | 7 +------ 6 files changed, 14 insertions(+), 22 deletions(-)
drivers/staging/rtl8188eu/core/rtw_ap.c +2 -2
@@ -104,7 +104,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,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (pbackup_remainder_ie && premainder_ie)memcpy (pbackup_remainder_ie, premainder_ie, remainder_ielen);
@@ -1168,7 +1168,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,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (pbackup_remainder_ie)memcpy (pbackup_remainder_ie, premainder_ie, remainder_ielen); }
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +1 -1
@@ -2573,7 +2573,7 @@ static unsigned int OnBeacon(struct adapter *padapter,if (!memcmp (GetAddr3Ptr (pframe), pnetwork->MacAddress,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 (*pbss),in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (pbss) {if (collect_bss_info (padapter, precv_frame, pbss) == _SUCCESS) {update_network (&pmlmepriv->cur_network.network, pbss, padapter, true);
drivers/staging/rtl8188eu/include/osdep_service.h +0 -3
@@ -61,9 +61,6 @@ static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)netif_tx_queue_stopped (netdev_get_tx_queue (pnetdev,3 )); } -u8 *_rtw_malloc (u32 sz); -#define rtw_malloc (sz) _rtw_malloc((sz)) -void _rtw_init_queue (struct __queue *pqueue);struct rtw_netdev_priv_indicator {
drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +9 -9
@@ -392,7 +392,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 + offsetof(struct ndis_802_11_wep , KeyMaterial); - pwep = (struct ndis_802_11_wep *)rtw_malloc (wep_total_len); + pwep =kmalloc (wep_total_len,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (!pwep) {RT_TRACE (_module_rtl871x_ioctl_os_c, _drv_err_, (" wpa_set_encryption: pwep allocate fail !!!\n" )); goto exit;
@@ -1862,7 +1862,7 @@ 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 =kmalloc (param_len,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (!param)return -1 ;
@@ -2027,7 +2027,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,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (!param) { ret = -ENOMEM ; goto out;
@@ -2236,7 +2236,7 @@ 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 + offsetof(struct ndis_802_11_wep , KeyMaterial); - pwep = (struct ndis_802_11_wep *)rtw_malloc (wep_total_len); + pwep =kmalloc (wep_total_len,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (!pwep) {DBG_88E (" r871x_set_encryption: pwep allocate fail !!!\n" ); goto exit;
@@ -2652,7 +2652,7 @@ static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, pmlmepriv->wps_beacon_ie =NULL ;if (ie_len >0 ) { - pmlmepriv->wps_beacon_ie =rtw_malloc (ie_len); + pmlmepriv->wps_beacon_ie =kmalloc (ie_len,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL ); pmlmepriv->wps_beacon_ie_len = ie_len;if (!pmlmepriv->wps_beacon_ie) {DBG_88E ("%s()-%d: rtw_malloc() ERROR!\n" , __func__, __LINE__);
@@ -2686,7 +2686,7 @@ static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *par pmlmepriv->wps_probe_resp_ie =NULL ;if (ie_len >0 ) { - pmlmepriv->wps_probe_resp_ie =rtw_malloc (ie_len); + pmlmepriv->wps_probe_resp_ie =kmalloc (ie_len,in_interrupt () ?GFP_ATOMIC :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__);
@@ -2715,7 +2715,7 @@ static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *par pmlmepriv->wps_assoc_resp_ie =NULL ;if (ie_len >0 ) { - pmlmepriv->wps_assoc_resp_ie =rtw_malloc (ie_len); + pmlmepriv->wps_assoc_resp_ie =kmalloc (ie_len,in_interrupt () ?GFP_ATOMIC :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__);
@@ -2814,7 +2814,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,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (!param) { ret = -ENOMEM ; goto out;
@@ -2924,7 +2924,7 @@ 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,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (!pmlmepriv->wps_probe_req_ie) {pr_info ("%s()-%d: rtw_malloc() ERROR!\n" , __func__, __LINE__); ret = -EINVAL ;
drivers/staging/rtl8188eu/os_dep/mlme_linux.c +1 -1
@@ -93,7 +93,7 @@ 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_, ("%s, authmode=%d\n" , __func__, authmode)); - buff =rtw_malloc (IW_CUSTOM_MAX ); + buff =kmalloc (IW_CUSTOM_MAX ,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (!buff)return ;memset (buff,0 ,IW_CUSTOM_MAX );
drivers/staging/rtl8188eu/os_dep/osdep_service.c +1 -6
@@ -13,11 +13,6 @@#include <linux/vmalloc.h> #include <rtw_ioctl_set.h> -u8 *_rtw_malloc (u32 sz) -{ -return kmalloc (sz,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL ); -} -void _rtw_init_queue (struct __queue *pqueue) {INIT_LIST_HEAD (&pqueue->queue);
@@ -79,7 +74,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,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );if (dup) { dup_len = src_len;memcpy (dup, src, dup_len);
Signature · 1 line
2.21.0
Quoted 17 lines · Ivan Safonov
rtw_mallocprevents the use of kmemdup/kzalloc and others.Signed-off-by Ivan Safonov <[email protected]>--- drivers/staging/rtl8188eu/core/rtw_ap.c | 4 ++-- drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 2 +- .../staging/rtl8188eu/include/osdep_service.h | 3 --- drivers/staging/rtl8188eu/os_dep/ioctl_linux.c | 18 +++++++++--------- drivers/staging/rtl8188eu/os_dep/mlme_linux.c | 2 +- .../staging/rtl8188eu/os_dep/osdep_service.c | 7 +------ 6 files changed, 14 insertions(+), 22 deletions(-)drivers/staging/rtl8188eu/core/rtw_ap.c +0
-0
drivers/staging/rtl8188eu/core/rtw_ap.c static void update_BCNTIM(struct adapter *padapter) · line 107
Quoted 5 lines
drivers/staging/rtl8188eu/core/rtw_ap.c +1
-1@@ -104,7 +104,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,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );
^^^^^^^^^^^^^
This stuff isn't right. It really should be checking if spinlocks are held or IRQs are disabled. And the only way to do that is by auditing the callers.
(The original rtw_malloc() implementation is buggy nonsense).
regards,
dan carpenter
Quoted 19 lines · Dan Carpenter
On Sun, Sep 08, 2019 at 12:00:26PM +0300, Ivan Safonov wrote >>
rtw_mallocprevents the use of kmemdup/kzalloc and others.Quoted 18 lines
Signed-off-by Ivan Safonov <[email protected]>--- drivers/staging/rtl8188eu/core/rtw_ap.c | 4 ++-- drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 2 +- .../staging/rtl8188eu/include/osdep_service.h | 3 --- drivers/staging/rtl8188eu/os_dep/ioctl_linux.c | 18 +++++++++--------- drivers/staging/rtl8188eu/os_dep/mlme_linux.c | 2 +- .../staging/rtl8188eu/os_dep/osdep_service.c | 7 +------ 6 files changed, 14 insertions(+), 22 deletions(-)drivers/staging/rtl8188eu/core/rtw_ap.c +0
-0@@ -104,7 +104,7 @@ static void update_BCNTIM(struct adapter *padapter) }
Quoted 7 lines
drivers/staging/rtl8188eu/core/rtw_ap.c static void update_BCNTIM(struct adapter *padapter) · line 107
Quoted 3 lines
drivers/staging/rtl8188eu/core/rtw_ap.c +1
-1if (remainder_ielen >0 ) { - pbackup_remainder_ie =rtw_malloc (remainder_ielen); + pbackup_remainder_ie =kmalloc (remainder_ielen,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );^^^^^^^^^^^^^This stuff isn't right. It really should be checking if spinlocks are held or IRQs are disabled. And the only way to do that is by auditing the callers.
I hope to make these changes later as separate independent patches. This patch do only one thing - remove rtw_malloc().
Quoted 6 lines
(The original
rtw_malloc()implementation is buggy nonsense).regards,
dan carpenter
Ivan Safonov.
Quoted 26 lines · Ivan Safonov
Quoted 22 lines · Dan Carpenter
On Sun, Sep 08, 2019 at 12:00:26PM +0300, Ivan Safonov wrote >>
rtw_mallocprevents the use of kmemdup/kzalloc and others.Quoted 16 lines
Signed-off-by Ivan Safonov <[email protected]>--- drivers/staging/rtl8188eu/core/rtw_ap.c | 4 ++-- drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 2 +- .../staging/rtl8188eu/include/osdep_service.h | 3 --- drivers/staging/rtl8188eu/os_dep/ioctl_linux.c | 18 +++++++++--------- drivers/staging/rtl8188eu/os_dep/mlme_linux.c | 2 +- .../staging/rtl8188eu/os_dep/osdep_service.c | 7 +------ 6 files changed, 14 insertions(+), 22 deletions(-)drivers/staging/rtl8188eu/core/rtw_ap.c +0
-0drivers/staging/rtl8188eu/core/rtw_ap.c static void update_BCNTIM(struct adapter *padapter) · line 106
Quoted 4 lines
drivers/staging/rtl8188eu/core/rtw_ap.c +1
-1@@ -104,7 +104,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,in_interrupt () ?GFP_ATOMIC :GFP_KERNEL );^^^^^^^^^^^^^Quoted 3 lines
This stuff isn't right. It really should be checking if spinlocks are held or IRQs are disabled. And the only way to do that is by auditing the callers.
Quoted 2 lines
I hope to make these changes later as separate independent patches. This patch do only one thing - remove
rtw_malloc().
No, just do that in one step.
regards,
dan carpenter