staging:r8188eu: refactor OnAction(): use switch instead table lookup
PATCH 1/2 staging:r8188eu: refactor OnAction(): use switch instead table lookup
The switch is easier to read and refactor.
--- drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 57 ++++++++++++------- .../staging/rtl8188eu/include/rtw_mlme_ext.h | 6 -- 2 files changed, 37 insertions(+), 26 deletions(-)
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +37 -20
@@ -3780,26 +3780,10 @@ static unsigned int DoReserved(struct adapter *padapter,return _SUCCESS; } -static struct action_handler OnAction_tbl[] = { - {RTW_WLAN_CATEGORY_SPECTRUM_MGMT ,"ACTION_SPECTRUM_MGMT" , on_action_spct}, - {RTW_WLAN_CATEGORY_QOS ,"ACTION_QOS" , &OnAction_qos}, - {RTW_WLAN_CATEGORY_DLS ,"ACTION_DLS" , &OnAction_dls}, - {RTW_WLAN_CATEGORY_BACK ,"ACTION_BACK" , &OnAction_back}, - {RTW_WLAN_CATEGORY_PUBLIC ,"ACTION_PUBLIC" , on_action_public}, - {RTW_WLAN_CATEGORY_RADIO_MEASUREMENT ,"ACTION_RADIO_MEASUREMENT" , &DoReserved}, - {RTW_WLAN_CATEGORY_FT ,"ACTION_FT" , &DoReserved}, - {RTW_WLAN_CATEGORY_HT ,"ACTION_HT" , &OnAction_ht}, - {RTW_WLAN_CATEGORY_SA_QUERY ,"ACTION_SA_QUERY" , &DoReserved}, - {RTW_WLAN_CATEGORY_WMM ,"ACTION_WMM" , &OnAction_wmm}, - {RTW_WLAN_CATEGORY_P2P ,"ACTION_P2P" , &OnAction_p2p}, -}; -static unsigned int OnAction (struct adapter *padapter,struct recv_frame *precv_frame) { -int i;unsigned char category; -struct action_handler *ptable;unsigned char *frame_body;u8 *pframe = precv_frame->pkt->data;
@@ -3807,11 +3791,44 @@ static unsigned int OnAction(struct adapter *padapter, category = frame_body[0 ]; -for (i =0 ; i <ARRAY_SIZE (OnAction_tbl); i++) { - ptable = &OnAction_tbl[i]; -if (category == ptable->num) - ptable->func (padapter, precv_frame); +switch (category) { +case RTW_WLAN_CATEGORY_SPECTRUM_MGMT : +on_action_spct (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_QOS : +OnAction_qos (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_DLS : +OnAction_dls (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_BACK : +OnAction_back (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_PUBLIC : +on_action_public (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_RADIO_MEASUREMENT : +DoReserved (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_FT : +DoReserved (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_HT : +OnAction_ht (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_SA_QUERY : +DoReserved (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_WMM : +OnAction_wmm (padapter, precv_frame); +break ; +case RTW_WLAN_CATEGORY_P2P : +OnAction_p2p (padapter, precv_frame); +break ; +default : +break ; } +return _SUCCESS; }
drivers/staging/rtl8188eu/include/rtw_mlme_ext.h +0 -6
@@ -227,12 +227,6 @@ struct mlme_handler {unsigned int (*func)(struct adapter *adapt,struct recv_frame *frame); }; -struct action_handler { -unsigned int num; -const char *str; -unsigned int (*func)(struct adapter *adapt,struct recv_frame *frame); -}; -struct ss_res {int state;int bss_cnt;
Signature · 1 line
2.26.2
PATCH 2/2 staging:r8188eu: remove dummy handlers from OnAction()
on_action_spct() do nothing, because rtw_get_stainfo() has no side effects. Other action handlers are trivial.
--- drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 95 ------------------- 1 file changed, 95 deletions(-)
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +0 -95
@@ -3517,56 +3517,6 @@ static unsigned int OnAtim(struct adapter *padapter,return _SUCCESS; } -static unsigned int on_action_spct (struct adapter *padapter, -struct recv_frame *precv_frame) -{ -struct sta_info *psta =NULL ; -struct sta_priv *pstapriv = &padapter->stapriv; -u8 *pframe = precv_frame->pkt->data; -u8 *frame_body = pframe +sizeof (struct ieee80211_hdr_3addr ); -u8 category; -u8 action; - -DBG_88E (FUNC_NDEV_FMT "\n" ,FUNC_NDEV_ARG (padapter->pnetdev)); - - psta =rtw_get_stainfo (pstapriv,GetAddr2Ptr (pframe)); - -if (!psta) - goto exit; - - category = frame_body[0 ]; -if (category !=RTW_WLAN_CATEGORY_SPECTRUM_MGMT ) - goto exit; - - action = frame_body[1 ]; -switch (action) { -case WLAN_ACTION_SPCT_MSR_REQ : -case WLAN_ACTION_SPCT_MSR_RPRT : -case WLAN_ACTION_SPCT_TPC_REQ : -case WLAN_ACTION_SPCT_TPC_RPRT : -break ; -case WLAN_ACTION_SPCT_CHL_SWITCH : -break ; -default : -break ; - } - -exit: -return _FAIL; -} - -static unsigned int OnAction_qos (struct adapter *padapter, -struct recv_frame *precv_frame) -{ -return _SUCCESS; -} - -static unsigned int OnAction_dls (struct adapter *padapter, -struct recv_frame *precv_frame) -{ -return _SUCCESS; -} -static unsigned int OnAction_back (struct adapter *padapter,struct recv_frame *precv_frame) {
@@ -3756,24 +3706,6 @@ static unsigned int on_action_public(struct adapter *padapter,return ret; } -static unsigned int OnAction_ht (struct adapter *padapter, -struct recv_frame *precv_frame) -{ -return _SUCCESS; -} - -static unsigned int OnAction_wmm (struct adapter *padapter, -struct recv_frame *precv_frame) -{ -return _SUCCESS; -} - -static unsigned int OnAction_p2p (struct adapter *padapter, -struct recv_frame *precv_frame) -{ -return _SUCCESS; -} -static unsigned int DoReserved (struct adapter *padapter,struct recv_frame *precv_frame) {
@@ -3792,39 +3724,12 @@ static unsigned int OnAction(struct adapter *padapter, category = frame_body[0 ];switch (category) { -case RTW_WLAN_CATEGORY_SPECTRUM_MGMT : -on_action_spct (padapter, precv_frame); -break ; -case RTW_WLAN_CATEGORY_QOS : -OnAction_qos (padapter, precv_frame); -break ; -case RTW_WLAN_CATEGORY_DLS : -OnAction_dls (padapter, precv_frame); -break ;case RTW_WLAN_CATEGORY_BACK :OnAction_back (padapter, precv_frame);break ;case RTW_WLAN_CATEGORY_PUBLIC :on_action_public (padapter, precv_frame);break ; -case RTW_WLAN_CATEGORY_RADIO_MEASUREMENT : -DoReserved (padapter, precv_frame); -break ; -case RTW_WLAN_CATEGORY_FT : -DoReserved (padapter, precv_frame); -break ; -case RTW_WLAN_CATEGORY_HT : -OnAction_ht (padapter, precv_frame); -break ; -case RTW_WLAN_CATEGORY_SA_QUERY : -DoReserved (padapter, precv_frame); -break ; -case RTW_WLAN_CATEGORY_WMM : -OnAction_wmm (padapter, precv_frame); -break ; -case RTW_WLAN_CATEGORY_P2P : -OnAction_p2p (padapter, precv_frame); -break ;default :break ; }
Signature · 1 line
2.26.2
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] staging:r8188eu: remove dummy handlers from OnAction()
Quoted 4 lines · Ivan Safonov
on_action_spct()do nothing, becausertw_get_stainfo()has no side effects. Other action handlers are trivial.Signed-off-by Ivan Safonov <[email protected]>
Same here, wrong driver name :(
Re: [PATCH 2/2] staging:r8188eu: remove dummy handlers from OnAction()
Quoted 8 lines · Greg Kroah-Hartman
Quoted 4 lines · Ivan Safonov
on_action_spct()do nothing, becausertw_get_stainfo()has no side effects. Other action handlers are trivial.Signed-off-by Ivan Safonov <[email protected]>Same here, wrong driver name :(
Driver name is "r8188eu"...
$ grep 'r8188eu' drivers/staging/rtl8188eu/include/drv_types.h #define DRV_NAME "r8188eu"
$ grep 'r8188eu' drivers/staging/rtl8188eu/os_dep/usb_intf.c -B1 -A7
static struct usb_driver rtl8188e_usb_drv = {
.name = "r8188eu",
.probe = rtw_drv_init,
.disconnect = rtw_dev_remove,
.id_table = rtw_usb_id_tbl,
.suspend = rtw_suspend,
.resume = rtw_resume,
.reset_resume = rtw_resume,
};$ cat drivers/staging/rtl8188eu/Kconfig
# SPDX-License-Identifier: GPL-2.0
config R8188EU
tristate "Realtek RTL8188EU Wireless LAN NIC driver"
depends on WLAN && USB && CFG80211
depends on m
select WIRELESS_EXT
select WEXT_PRIV
select LIB80211
select LIB80211_CRYPT_WEP
select LIB80211_CRYPT_CCMP
help
This option adds the Realtek RTL8188EU USB device such as
TP-Link TL-WN725N.
If built as a module, it will be called r8188eu.if R8188EU
config 88EU_AP_MODE
bool "Realtek RTL8188EU AP mode"
default y
help
This option enables Access Point mode. Unless you know that
your system
will never be used as an AP, or the target system has limited
memory,
"Y" should be selected.
endif
Greg Kroah-Hartman
maintainerRe: [PATCH 2/2] staging:r8188eu: remove dummy handlers from OnAction()
Quoted 5 lines · Ivan Safonov
Quoted 4 lines · Greg Kroah-Hartman
Quoted 3 lines · Ivan Safonov
on_action_spct()do nothing, becausertw_get_stainfo()has no side effects. Other action handlers are trivial.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Ivan Safonov <[email protected]>Same here, wrong driver name :(
Driver name is "r8188eu"...
$ grep 'r8188eu' drivers/staging/rtl8188eu/include/drv_types.h
Directory name is "rtl8188eu", so something needs to be fixed up here to remove confusion like this :)
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 1 line · Ivan Safonov
The switch is easier to read and refactor.
Your subject line is incorrect :(