Skip to contentSkip to conversation

staging: rtl8723bs: remove GEN_CMD_CODE macro and callback array

PATCH In review Xiyuan Guo 2 participants 3 messages Apr 3 – Jul 7 Staging

lore
Share & tools
lore

Xiyuan Guo

author
#0 lore raw

PATCH v3 1/1 staging: rtl8723bs: remove GEN_CMD_CODE macro and callback array

The GEN_CMD_CODE macro and the rtw_cmd_callback function pointer array add unnecessary layers of indirection and make the code difficult to follow. Remove the GEN_CMD_CODE macro and replace the function pointer array dispatcher in rtw_cmd_thread() with a direct switch statement.

Additionally, rename the associated command enums from CamelCase to UPPERCASE_SNAKE_CASE to comply with the standard Linux kernel coding style.

---
Change in v3:
- Dropped unrelated whitespace cleanup on the #endif comment.

Changes in v2:
- Fixed compilation error caused by missed CamelCase conversions.
- Restored accidentally deleted todo comment in rtw_cmd_thread().
- Renamed command enums from CamelCase to UPPERCASE_SNAKE_CASE.

 drivers/staging/rtl8723bs/core/rtw_ap.c       |   4 +-
 drivers/staging/rtl8723bs/core/rtw_cmd.c      | 157 ++++++-----------
 drivers/staging/rtl8723bs/core/rtw_mlme.c     |   4 +-
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c |  20 +--
 drivers/staging/rtl8723bs/include/rtw_cmd.h   | 162 +++++++++---------
 .../staging/rtl8723bs/include/rtw_mlme_ext.h  |  14 +-
 6 files changed, 147 insertions(+), 214 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ap.c +2 -2
index 4cdcdddf6b33..b9586b339095 100644
@@ -1237,7 +1237,7 @@ u8 rtw_ap_set_pairwise_key(struct adapter *padapter, struct sta_info *psta)
 		goto exit;
 	}
 
-	init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
+	init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, SET_STA_KEY);
 
 	psetstakey_para->algorithm = (u8)psta->dot118021XPrivacy;
 
@@ -1300,7 +1300,7 @@ static int rtw_ap_set_key(struct adapter *padapter,
 
 	memcpy(&psetkeyparm->key[0], key, keylen);
 
-	pcmd->cmdcode = _SetKey_CMD_;
+	pcmd->cmdcode = SET_KEY;
 	pcmd->parmbuf = (u8 *)psetkeyparm;
 	pcmd->cmdsz =  (sizeof(struct setkey_parm));
 	pcmd->rsp = NULL;
drivers/staging/rtl8723bs/core/rtw_cmd.c +49 -108

308 lines not on this page · raw message

drivers/staging/rtl8723bs/core/rtw_mlme.c +2 -2
index 5516593bc8ab..6e2b4fc2f096 100644
@@ -1881,7 +1881,7 @@ signed int rtw_set_auth(struct adapter *adapter, struct security_priv *psecurity
 
 	psetauthparm->mode = (unsigned char)psecuritypriv->dot11AuthAlgrthm;
 
-	pcmd->cmdcode = _SetAuth_CMD_;
+	pcmd->cmdcode = SET_AUTH;
 	pcmd->parmbuf = (unsigned char *)psetauthparm;
 	pcmd->cmdsz =  (sizeof(struct setauth_parm));
 	pcmd->rsp = NULL;
@@ -1952,7 +1952,7 @@ signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecurityp
 			goto exit;
 		}
 
-		pcmd->cmdcode = _SetKey_CMD_;
+		pcmd->cmdcode = SET_KEY;
 		pcmd->parmbuf = (u8 *)psetkeyparm;
 		pcmd->cmdsz =  (sizeof(struct setkey_parm));
 		pcmd->rsp = NULL;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +10 -10
index 5f00fe282d1b..3e71021bb8c8 100644
@@ -4391,7 +4391,7 @@ void report_survey_event(struct adapter *padapter, union recv_frame *precv_frame
 
 	INIT_LIST_HEAD(&pcmd_obj->list);
 
-	pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
+	pcmd_obj->cmdcode = SET_MLME_EVT;
 	pcmd_obj->cmdsz = cmdsz;
 	pcmd_obj->parmbuf = pevtcmd;
 
@@ -4444,7 +4444,7 @@ void report_surveydone_event(struct adapter *padapter)
 
 	INIT_LIST_HEAD(&pcmd_obj->list);
 
-	pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
+	pcmd_obj->cmdcode = SET_MLME_EVT;
 	pcmd_obj->cmdsz = cmdsz;
 	pcmd_obj->parmbuf = pevtcmd;
 
@@ -4489,7 +4489,7 @@ void report_join_res(struct adapter *padapter, int res)
 
 	INIT_LIST_HEAD(&pcmd_obj->list);
 
-	pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
+	pcmd_obj->cmdcode = SET_MLME_EVT;
 	pcmd_obj->cmdsz = cmdsz;
 	pcmd_obj->parmbuf = pevtcmd;
 
@@ -4498,7 +4498,7 @@ void report_join_res(struct adapter *padapter, int res)
 
 	pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
 	pc2h_evt_hdr->len = sizeof(struct joinbss_event);
-	pc2h_evt_hdr->ID = GEN_EVT_CODE(_JoinBss);
+	pc2h_evt_hdr->ID = GEN_EVT_CODE(JOIN_BSS);
 	pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
 
 	pjoinbss_evt = (struct joinbss_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
@@ -4538,7 +4538,7 @@ void report_wmm_edca_update(struct adapter *padapter)
 
 	INIT_LIST_HEAD(&pcmd_obj->list);
 
-	pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
+	pcmd_obj->cmdcode = SET_MLME_EVT;
 	pcmd_obj->cmdsz = cmdsz;
 	pcmd_obj->parmbuf = pevtcmd;
 
@@ -4584,7 +4584,7 @@ void report_del_sta_event(struct adapter *padapter, unsigned char *MacAddr, unsi
 
 	INIT_LIST_HEAD(&pcmd_obj->list);
 
-	pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
+	pcmd_obj->cmdcode = SET_MLME_EVT;
 	pcmd_obj->cmdsz = cmdsz;
 	pcmd_obj->parmbuf = pevtcmd;
 
@@ -4635,7 +4635,7 @@ void report_add_sta_event(struct adapter *padapter, unsigned char *MacAddr, int
 
 	INIT_LIST_HEAD(&pcmd_obj->list);
 
-	pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
+	pcmd_obj->cmdcode = SET_MLME_EVT;
 	pcmd_obj->cmdsz = cmdsz;
 	pcmd_obj->parmbuf = pevtcmd;
 
@@ -5085,7 +5085,7 @@ void survey_timer_hdl(struct timer_list *t)
 			return;
 		}
 
-		init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
+		init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, SITE_SURVEY);
 		rtw_enqueue_cmd(pcmdpriv, ph2c);
 	}
 }
@@ -5696,7 +5696,7 @@ u8 chk_bmc_sleepq_cmd(struct adapter *padapter)
 		goto exit;
 	}
 
-	init_h2fwcmd_w_parm_no_parm_rsp(ph2c, GEN_CMD_CODE(_ChkBMCSleepq));
+	init_h2fwcmd_w_parm_no_parm_rsp(ph2c, CHK_BMC_SLEEPQ);
 
 	res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 
@@ -5734,7 +5734,7 @@ u8 set_tx_beacon_cmd(struct adapter *padapter)
 				      pmlmeinfo->hidden_ssid_mode);
 	ptxBeacon_parm->network.ie_length += len_diff;
 
-	init_h2fwcmd_w_parm_no_rsp(ph2c, ptxBeacon_parm, GEN_CMD_CODE(_TX_Beacon));
+	init_h2fwcmd_w_parm_no_rsp(ph2c, ptxBeacon_parm, TX_BEACON);
 
 	res = rtw_enqueue_cmd(pcmdpriv, ph2c);
 
drivers/staging/rtl8723bs/include/rtw_cmd.h +77 -85

178 lines not on this page · raw message

drivers/staging/rtl8723bs/include/rtw_mlme_ext.h +7 -7
index 95769f90d196..4f508c91cecd 100644
@@ -679,18 +679,18 @@ void rtw_dummy_event_callback(struct adapter *adapter, u8 *pbuf);
 void rtw_fwdbg_event_callback(struct adapter *adapter, u8 *pbuf);
 
 enum {
-	GEN_EVT_CODE(_Read_MACREG) = 0, /*0*/
-	GEN_EVT_CODE(_Read_BBREG),
-	GEN_EVT_CODE(_Read_RFREG),
-	GEN_EVT_CODE(_Read_EEPROM),
-	GEN_EVT_CODE(_Read_EFUSE),
-	GEN_EVT_CODE(_Read_CAM),			/*5*/
+	GEN_EVT_CODE(READ_MACREG) = 0, /*0*/
+	GEN_EVT_CODE(READ_BBREG),
+	GEN_EVT_CODE(READ_RFREG),
+	GEN_EVT_CODE(READ_EEPROM),
+	GEN_EVT_CODE(READ_EFUSE),
+	GEN_EVT_CODE(READ_CAM),			/*5*/
 	GEN_EVT_CODE(_Get_BasicRate),
 	GEN_EVT_CODE(_Get_DataRate),
 	GEN_EVT_CODE(_Survey),	 /*8*/
 	GEN_EVT_CODE(_SurveyDone),	 /*9*/
 
-	GEN_EVT_CODE(_JoinBss), /*10*/
+	GEN_EVT_CODE(JOIN_BSS), /*10*/
 	GEN_EVT_CODE(_AddSTA),
 	GEN_EVT_CODE(_DelSTA),
 	GEN_EVT_CODE(_AtimDone),
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 10 lines · Xiyuan Guo

The GEN_CMD_CODE macro and the rtw_cmd_callback function pointer array add unnecessary layers of indirection and make the code difficult to follow. Remove the GEN_CMD_CODE macro and replace the function pointer array dispatcher in rtw_cmd_thread() with a direct switch statement.

Additionally, rename the associated command enums from CamelCase to UPPERCASE_SNAKE_CASE to comply with the standard Linux kernel coding style.

I like the idea, but this worries me as now you just dropped a bunch of "unused" entries that kind of documented things. Have you tested this change on a device this driver controls to verify it still works?

thanks,

greg k-h

maintainer
#2 lore raw
In reply to Xiyuan Guo
Quoted 5 lines · Xiyuan Guo

The GEN_CMD_CODE macro and the rtw_cmd_callback function pointer array add unnecessary layers of indirection and make the code difficult to follow. Remove the GEN_CMD_CODE macro and replace the function pointer array dispatcher in rtw_cmd_thread() with a direct switch statement.

Quoted 8 lines

Additionally, rename the associated command enums from CamelCase to UPPERCASE_SNAKE_CASE to comply with the standard Linux kernel coding style.

---
Change in v3:
- Dropped unrelated whitespace cleanup on the #endif comment.

No longer applies to the tree :(

Also, I'd really like this to be tested on real hardware as you are doing a lot of changes that are not necessarily just "coding style" issues.

thanks,
greg k-h