staging: rtl8723bs: core: Refactor nested if-else
PATCH v2 1/1 staging: rtl8723bs: core: Refactor nested if-else
Refactor nested if-else to avoid deep indentations. There is no change in the logic of the new code, however, now it is simple because it gets rid of five unnecessary else conditionals and it combines nested if into single if-else-if. This refactor also leads to fix warning detected by checkpatch.pl:
WARNING: Too many leading tabs - consider code refactoring
---
Changes in v2: Fix the bug of not handling properly the else logic when p is not null in else-if. Also, reword the subject line and break it up at 72 columns.
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +29 -40
@@ -1192,50 +1192,39 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) p = pframe +WLAN_HDR_A3_LEN + ie_offset; ie_len =0 ;for (;;) { p =rtw_get_ie (p,WLAN_EID_VENDOR_SPECIFIC , &ie_len, pkt_len -WLAN_HDR_A3_LEN - ie_offset); -if (p) { -if (!memcmp (p+2 ,WMM_IE ,6 )) { - - pstat->flags |=WLAN_STA_WME ; - - pstat->qos_option =1 ; - pstat->qos_info = *(p+8 ); - - pstat->max_sp_len = (pstat->qos_info>>5 )&0x3 ; - -if ((pstat->qos_info&0xf ) !=0xf ) - pstat->has_legacy_ac = true; -else - pstat->has_legacy_ac = false; - -if (pstat->qos_info&0xf ) { -if (pstat->qos_info&BIT (0 )) - pstat->uapsd_vo =BIT (0 )|BIT (1 ); -else - pstat->uapsd_vo =0 ; - -if (pstat->qos_info&BIT (1 )) - pstat->uapsd_vi =BIT (0 )|BIT (1 ); -else - pstat->uapsd_vi =0 ; - -if (pstat->qos_info&BIT (2 )) - pstat->uapsd_bk =BIT (0 )|BIT (1 ); -else - pstat->uapsd_bk =0 ; - -if (pstat->qos_info&BIT (3 )) - pstat->uapsd_be =BIT (0 )|BIT (1 ); -else - pstat->uapsd_be =0 ; - - } - -break ; +if (p &&memcmp (p+2 ,WMM_IE ,6 )) { + p = p + ie_len +2 ; + }else if (p && !memcmp (p+2 ,WMM_IE ,6 )) { + pstat->flags |=WLAN_STA_WME ; + pstat->qos_option =1 ; + pstat->qos_info = *(p+8 ); + pstat->max_sp_len = (pstat->qos_info>>5 )&0x3 ; + + pstat->has_legacy_ac = false; +if ((pstat->qos_info&0xf ) !=0xf ) + pstat->has_legacy_ac = true; + +if (pstat->qos_info&0xf ) { + pstat->uapsd_vo =0 ; +if (pstat->qos_info&BIT (0 )) + pstat->uapsd_vo =BIT (0 )|BIT (1 ); + + pstat->uapsd_vi =0 ; +if (pstat->qos_info&BIT (1 )) + pstat->uapsd_vi =BIT (0 )|BIT (1 ); + + pstat->uapsd_bk =0 ; +if (pstat->qos_info&BIT (2 )) + pstat->uapsd_bk =BIT (0 )|BIT (1 ); + + pstat->uapsd_be =0 ; +if (pstat->qos_info&BIT (3 )) + pstat->uapsd_be =BIT (0 )|BIT (1 ); } +break ; }else {break ; } - p = p + ie_len +2 ; } }
Signature · 1 line
2.25.1
Quoted 57 lines · Kushal Kothari
Refactor nested if-else to avoid deep indentations. There is no change in the logic of the new code, however, now it is simple because it gets rid of five unnecessary else conditionals and it combines nested if into single if-else-if. This refactor also leads to fix warning detected by checkpatch.pl:
WARNING: Too many leading tabs - consider code refactoringSigned-off-by Kushal Kothari <[email protected]>---
Changes in v2: Fix the bug of not handling properly the else logic when p is not null in else-if. Also, reword the subject line and break it up at 72 columns.
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-)drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-32@@ -1192,50 +1192,39 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) p = pframe +WLAN_HDR_A3_LEN + ie_offset; ie_len =0 ;for (;;) { p =rtw_get_ie (p,WLAN_EID_VENDOR_SPECIFIC , &ie_len, pkt_len -WLAN_HDR_A3_LEN - ie_offset); -if (p) { -if (!memcmp (p+2 ,WMM_IE ,6 )) { - - pstat->flags |=WLAN_STA_WME ; - - pstat->qos_option =1 ; - pstat->qos_info = *(p+8 ); - - pstat->max_sp_len = (pstat->qos_info>>5 )&0x3 ; - -if ((pstat->qos_info&0xf ) !=0xf ) - pstat->has_legacy_ac = true; -else - pstat->has_legacy_ac = false; - -if (pstat->qos_info&0xf ) { -if (pstat->qos_info&BIT (0 )) - pstat->uapsd_vo =BIT (0 )|BIT (1 ); -else - pstat->uapsd_vo =0 ; - -if (pstat->qos_info&BIT (1 )) - pstat->uapsd_vi =BIT (0 )|BIT (1 ); -else - pstat->uapsd_vi =0 ; - -if (pstat->qos_info&BIT (2 )) - pstat->uapsd_bk =BIT (0 )|BIT (1 ); -else - pstat->uapsd_bk =0 ; - -if (pstat->qos_info&BIT (3 ))
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1197
Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +3
-7- pstat->uapsd_be =BIT (0 )|BIT (1 ); - else - pstat->uapsd_be = 0; - - } - -break ; +if (p &&memcmp (p+2 ,WMM_IE ,6 )) { + p = p + ie_len +2 ; + }else if (p && !memcmp (p+2 ,WMM_IE ,6 )) {
I would think of something,
for(;;) {
p = rtw_get_ie(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
if (p) {
if (memcmp(p+2, WMM_IE, 6)) {
p = p + ie_len + 2;
continue;
}
pstat->flags |= WLAN_STA_WME;
...
}
/* Here we will reach only if p is NULL or its required entry */
break;
}Can you please check if this works well. Thanks. Also, wanted to check how are you testing these changes ?
Quoted 25 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +24
-0+ pstat->flags |=WLAN_STA_WME ; + pstat->qos_option =1 ; + pstat->qos_info = *(p+8 ); + pstat->max_sp_len = (pstat->qos_info>>5 )&0x3 ; + + pstat->has_legacy_ac = false; +if ((pstat->qos_info&0xf ) !=0xf ) + pstat->has_legacy_ac = true; + +if (pstat->qos_info&0xf ) { + pstat->uapsd_vo =0 ; +if (pstat->qos_info&BIT (0 )) + pstat->uapsd_vo =BIT (0 )|BIT (1 ); + + pstat->uapsd_vi =0 ; +if (pstat->qos_info&BIT (1 )) + pstat->uapsd_vi =BIT (0 )|BIT (1 ); + + pstat->uapsd_bk =0 ; +if (pstat->qos_info&BIT (2 )) + pstat->uapsd_bk =BIT (0 )|BIT (1 ); + + pstat->uapsd_be =0 ; +if (pstat->qos_info&BIT (3 ))
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1230
Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +2
-1+ pstat->uapsd_be =BIT (0 )|BIT (1 ); } +break ; }else {break ; } - p = p + ie_len +2 ; } }
Regards,
~Praveen.
Quoted 1 line
Can you please check if this works well. Thanks.
checkpatch.pl again warns of
"WARNING: Too many leading tabs - consider code refactoring" when adding another if loop on top .
Quoted 149 lines · Praveen Kumar
Quoted 10 lines · Kushal Kothari
Refactor nested if-else to avoid deep indentations. There is no change in the logic of the new code, however, now it is simple because it gets rid of five unnecessary else conditionals and it combines nested if into single if-else-if. This refactor also leads to fix warning detected by checkpatch.pl:
WARNING: Too many leading tabs - consider code refactoringSigned-off-by Kushal Kothari <[email protected]>---
Review
Quoted 8 lines
Changes in v2: Fix the bug of not handling properly the else logic when p is not null in else-if. Also, reword the subject line and break it up at 72 columns.
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-)(quoted diff) +0
-0
b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.cdrivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter
Quoted 4 lines
index
0f82f5031c43..267d853b1514100644drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-0@@ -1192,50 +1192,39 @@ unsigned int OnAssocReq(struct adapter*padapter, union
recv_frame*precv_frame)drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-0p = pframe +WLAN_HDR_A3_LEN + ie_offset; ie_len =0 ;for (;;) { p = rtw_get_ie(p, WLAN_EID_VENDOR_SPECIFIC,
&ie_len,pkt_len-WLAN_HDR_A3_LEN-ie_offset);drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 9 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-9-if (p) { -if (!memcmp (p+2 ,WMM_IE ,6 )) { - - pstat->flags |=WLAN_STA_WME ; - - pstat->qos_option =1 ; - pstat->qos_info = *(p+8 ); - - pstat->max_sp_len =(pstat->qos_info>>5)&0x3;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if ((pstat->qos_info&0xf ) !=0xf ) - pstat->has_legacy_ac =true;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1208
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->has_legacy_ac =false;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-4- -if (pstat->qos_info&0xf ) { -if (pstat->qos_info&BIT (0 )) - pstat->uapsd_vo =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1214
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_vo =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if (pstat->qos_info&BIT (1 )) - pstat->uapsd_vi =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1219
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_vi =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if (pstat->qos_info&BIT (2 )) - pstat->uapsd_bk =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1224
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_bk =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if (pstat->qos_info&BIT (3 )) - pstat->uapsd_be =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1229
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_be =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1197
Quoted 7 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +3
-4- - } - -break ; +if (p &&memcmp (p+2 ,WMM_IE ,6 )) { + p = p + ie_len +2 ; + }else if (p && !memcmp (p+2 ,WMM_IE ,6 )) {I would think of something,
for(;;) {
p = rtw_get_ie(p,WLAN_EID_VENDOR_SPECIFIC,&ie_len,pkt_len-WLAN_HDR_A3_LEN - ie_offset); if (p) { if (memcmp(p+2, WMM_IE, 6)) { p = p + ie_len + 2; continue; } pstat->flags |= WLAN_STA_WME; ... } /* Here we will reach only if p is NULL or its required entry */ break; }Can you please check if this works well. Thanks. Also, wanted to check how are you testing these changes ?
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ pstat->flags |=WLAN_STA_WME ; + pstat->qos_option =1 ; + pstat->qos_info = *(p+8 ); + pstat->max_sp_len =(pstat->qos_info>>5)&0x3;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 9 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +9
-0+ + pstat->has_legacy_ac = false; +if ((pstat->qos_info&0xf ) !=0xf ) + pstat->has_legacy_ac = true; + +if (pstat->qos_info&0xf ) { + pstat->uapsd_vo =0 ; +if (pstat->qos_info&BIT (0 )) + pstat->uapsd_vo =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ + pstat->uapsd_vi =0 ; +if (pstat->qos_info&BIT (1 )) + pstat->uapsd_vi =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ + pstat->uapsd_bk =0 ; +if (pstat->qos_info&BIT (2 )) + pstat->uapsd_bk =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ + pstat->uapsd_be =0 ; +if (pstat->qos_info&BIT (3 )) + pstat->uapsd_be =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1230
Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +1
-1} +break ; }else {break ; } - p = p + ie_len +2 ; } }Regards,
~Praveen.
Quoted 6 lines · kushal kothari
Quoted 1 line
Can you please check if this works well. Thanks.
checkpatch.pl again warns of
"WARNING: Too many leading tabs - consider code refactoring" when adding another if loop on top .
Thanks for checking. The whole intention was to reduce unnecessary memcmp.
These operations are heavy and performing same comparison twice, IMHO needs to be thought well. But, I'll wait for others to comment on this. Thanks.
Regards,
~Praveen.
Quoted 153 lines
Quoted 149 lines · Praveen Kumar
Quoted 10 lines · Kushal Kothari
Refactor nested if-else to avoid deep indentations. There is no change in the logic of the new code, however, now it is simple because it gets rid of five unnecessary else conditionals and it combines nested if into single if-else-if. This refactor also leads to fix warning detected by checkpatch.pl:
WARNING: Too many leading tabs - consider code refactoringSigned-off-by Kushal Kothari <[email protected]>---
Review
Quoted 8 lines
Changes in v2: Fix the bug of not handling properly the else logic when p is not null in else-if. Also, reword the subject line and break it up at 72 columns.
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-)(quoted diff) +0
-0
b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.cdrivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter
Quoted 4 lines
index
0f82f5031c43..267d853b1514100644drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-0@@ -1192,50 +1192,39 @@ unsigned int OnAssocReq(struct adapter*padapter, union
recv_frame*precv_frame)drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-0p = pframe +WLAN_HDR_A3_LEN + ie_offset; ie_len =0 ;for (;;) { p = rtw_get_ie(p, WLAN_EID_VENDOR_SPECIFIC,
&ie_len,pkt_len-WLAN_HDR_A3_LEN-ie_offset);drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 9 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-9-if (p) { -if (!memcmp (p+2 ,WMM_IE ,6 )) { - - pstat->flags |=WLAN_STA_WME ; - - pstat->qos_option =1 ; - pstat->qos_info = *(p+8 ); - - pstat->max_sp_len =(pstat->qos_info>>5)&0x3;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if ((pstat->qos_info&0xf ) !=0xf ) - pstat->has_legacy_ac =true;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1208
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->has_legacy_ac =false;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-4- -if (pstat->qos_info&0xf ) { -if (pstat->qos_info&BIT (0 )) - pstat->uapsd_vo =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1214
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_vo =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if (pstat->qos_info&BIT (1 )) - pstat->uapsd_vi =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1219
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_vi =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if (pstat->qos_info&BIT (2 )) - pstat->uapsd_bk =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1224
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_bk =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if (pstat->qos_info&BIT (3 )) - pstat->uapsd_be =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1229
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_be =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1197
Quoted 7 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +3
-4- - } - -break ; +if (p &&memcmp (p+2 ,WMM_IE ,6 )) { + p = p + ie_len +2 ; + }else if (p && !memcmp (p+2 ,WMM_IE ,6 )) {I would think of something,
for(;;) {
p = rtw_get_ie(p,WLAN_EID_VENDOR_SPECIFIC,&ie_len,pkt_len-WLAN_HDR_A3_LEN - ie_offset); if (p) { if (memcmp(p+2, WMM_IE, 6)) { p = p + ie_len + 2; continue; } pstat->flags |= WLAN_STA_WME; ... } /* Here we will reach only if p is NULL or its required entry */ break; }Can you please check if this works well. Thanks. Also, wanted to check how are you testing these changes ?
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ pstat->flags |=WLAN_STA_WME ; + pstat->qos_option =1 ; + pstat->qos_info = *(p+8 ); + pstat->max_sp_len =(pstat->qos_info>>5)&0x3;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 9 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +9
-0+ + pstat->has_legacy_ac = false; +if ((pstat->qos_info&0xf ) !=0xf ) + pstat->has_legacy_ac = true; + +if (pstat->qos_info&0xf ) { + pstat->uapsd_vo =0 ; +if (pstat->qos_info&BIT (0 )) + pstat->uapsd_vo =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ + pstat->uapsd_vi =0 ; +if (pstat->qos_info&BIT (1 )) + pstat->uapsd_vi =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ + pstat->uapsd_bk =0 ; +if (pstat->qos_info&BIT (2 )) + pstat->uapsd_bk =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ + pstat->uapsd_be =0 ; +if (pstat->qos_info&BIT (3 )) + pstat->uapsd_be =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1230
Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +1
-1} +break ; }else {break ; } - p = p + ie_len +2 ; } }Regards,
~Praveen.
Quoted 68 lines · Kushal Kothari
Refactor nested if-else to avoid deep indentations. There is no change in the logic of the new code, however, now it is simple because it gets rid of five unnecessary else conditionals and it combines nested if into single if-else-if. This refactor also leads to fix warning detected by checkpatch.pl:
WARNING: Too many leading tabs - consider code refactoringSigned-off-by Kushal Kothari <[email protected]>---
Changes in v2: Fix the bug of not handling properly the else logic when p is not null in else-if. Also, reword the subject line and break it up at 72 columns.
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-)drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-39@@ -1192,50 +1192,39 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) p = pframe +WLAN_HDR_A3_LEN + ie_offset; ie_len =0 ;for (;;) { p =rtw_get_ie (p,WLAN_EID_VENDOR_SPECIFIC , &ie_len, pkt_len -WLAN_HDR_A3_LEN - ie_offset); -if (p) { -if (!memcmp (p+2 ,WMM_IE ,6 )) { - - pstat->flags |=WLAN_STA_WME ; - - pstat->qos_option =1 ; - pstat->qos_info = *(p+8 ); - - pstat->max_sp_len = (pstat->qos_info>>5 )&0x3 ; - -if ((pstat->qos_info&0xf ) !=0xf ) - pstat->has_legacy_ac = true; -else - pstat->has_legacy_ac = false; - -if (pstat->qos_info&0xf ) { -if (pstat->qos_info&BIT (0 )) - pstat->uapsd_vo =BIT (0 )|BIT (1 ); -else - pstat->uapsd_vo =0 ; - -if (pstat->qos_info&BIT (1 )) - pstat->uapsd_vi =BIT (0 )|BIT (1 ); -else - pstat->uapsd_vi =0 ; - -if (pstat->qos_info&BIT (2 )) - pstat->uapsd_bk =BIT (0 )|BIT (1 ); -else - pstat->uapsd_bk =0 ; - -if (pstat->qos_info&BIT (3 )) - pstat->uapsd_be =BIT (0 )|BIT (1 ); -else - pstat->uapsd_be =0 ; - - } - -break ; +if (p &&memcmp (p+2 ,WMM_IE ,6 )) { + p = p + ie_len +2 ; + }else if (p && !memcmp (p+2 ,WMM_IE ,6 )) { + pstat->flags |=WLAN_STA_WME ;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1208
Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +10
-0+ pstat->qos_option =1 ; + pstat->qos_info = *(p+8 ); + pstat->max_sp_len = (pstat->qos_info>>5 )&0x3 ; + + pstat->has_legacy_ac = false; +if ((pstat->qos_info&0xf ) !=0xf ) + pstat->has_legacy_ac = true; + +if (pstat->qos_info&0xf ) { + pstat->uapsd_vo =0 ;
This variable and other variables below are set to 0 just before the loop, so the initialization here can be removed.
Quoted 26 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +15
-1+if (pstat->qos_info&BIT (0 )) + pstat->uapsd_vo =BIT (0 )|BIT (1 ); + + pstat->uapsd_vi =0 ; +if (pstat->qos_info&BIT (1 )) + pstat->uapsd_vi =BIT (0 )|BIT (1 ); + + pstat->uapsd_bk =0 ; +if (pstat->qos_info&BIT (2 )) + pstat->uapsd_bk =BIT (0 )|BIT (1 ); + + pstat->uapsd_be =0 ; +if (pstat->qos_info&BIT (3 )) + pstat->uapsd_be =BIT (0 )|BIT (1 ); } +break ; }else {break ; } - p = p + ie_len +2 ; } }Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours, Mike.
Yes!
Also initializing variable pstat->has_legacy_ac = false; //false which is previously set to true before the loop so it can be removed too.
Quoted 133 lines · Mike Rapoport
Quoted 10 lines · Kushal Kothari
Refactor nested if-else to avoid deep indentations. There is no change in the logic of the new code, however, now it is simple because it gets rid of five unnecessary else conditionals and it combines nested if into single if-else-if. This refactor also leads to fix warning detected by checkpatch.pl:
WARNING: Too many leading tabs - consider code refactoringSigned-off-by Kushal Kothari <[email protected]>---
Review
Quoted 8 lines
Changes in v2: Fix the bug of not handling properly the else logic when p is not null in else-if. Also, reword the subject line and break it up at 72 columns.
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-)(quoted diff) +0
-0
b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.cdrivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter
Quoted 4 lines
index
0f82f5031c43..267d853b1514100644drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-0@@ -1192,50 +1192,39 @@ unsigned int OnAssocReq(struct adapter*padapter, union
recv_frame*precv_frame)drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-0p = pframe +WLAN_HDR_A3_LEN + ie_offset; ie_len =0 ;for (;;) { p = rtw_get_ie(p, WLAN_EID_VENDOR_SPECIFIC,
&ie_len,pkt_len-WLAN_HDR_A3_LEN-ie_offset);drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 9 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-9-if (p) { -if (!memcmp (p+2 ,WMM_IE ,6 )) { - - pstat->flags |=WLAN_STA_WME ; - - pstat->qos_option =1 ; - pstat->qos_info = *(p+8 ); - - pstat->max_sp_len =(pstat->qos_info>>5)&0x3;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if ((pstat->qos_info&0xf ) !=0xf ) - pstat->has_legacy_ac =true;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1208
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->has_legacy_ac =false;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-4- -if (pstat->qos_info&0xf ) { -if (pstat->qos_info&BIT (0 )) - pstat->uapsd_vo =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1214
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_vo =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if (pstat->qos_info&BIT (1 )) - pstat->uapsd_vi =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1219
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_vi =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if (pstat->qos_info&BIT (2 )) - pstat->uapsd_bk =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1224
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_bk =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 3 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-3- -if (pstat->qos_info&BIT (3 )) - pstat->uapsd_be =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1229
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-2-else - pstat->uapsd_be =0;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 11 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +7
-4- - } - -break ; +if (p &&memcmp (p+2 ,WMM_IE ,6 )) { + p = p + ie_len +2 ; + }else if (p && !memcmp (p+2 ,WMM_IE ,6 )) { + pstat->flags |=WLAN_STA_WME ; + pstat->qos_option =1 ; + pstat->qos_info = *(p+8 ); + pstat->max_sp_len =(pstat->qos_info>>5)&0x3;
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) · line 1208
Quoted 7 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +7
-0+ + pstat->has_legacy_ac = false; +if ((pstat->qos_info&0xf ) !=0xf ) + pstat->has_legacy_ac = true; + +if (pstat->qos_info&0xf ) { + pstat->uapsd_vo =0 ;This variable and other variables below are set to 0 just before the loop, so the initialization here can be removed.
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter · line 1210
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +2
-0+if (pstat->qos_info&BIT (0 )) + pstat->uapsd_vo =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ + pstat->uapsd_vi =0 ; +if (pstat->qos_info&BIT (1 )) + pstat->uapsd_vi =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ + pstat->uapsd_bk =0 ; +if (pstat->qos_info&BIT (2 )) + pstat->uapsd_bk =BIT(0)|BIT(1);
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
Quoted 4 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +4
-0+ + pstat->uapsd_be =0 ; +if (pstat->qos_info&BIT (3 )) + pstat->uapsd_be =BIT(0)|BIT(1);
Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +1
-2} +break ; }else {break ; } - p = p + ie_len +2 ; } } --Quoted 2 lines
2.25.1
--
Sincerely yours,
Mike.
Hi,
Quoted 3 lines · kushal kothari
Yes!
Also initializing variablepstat->has_legacy_ac= false; //false which is previously set to true before the loop so it can be removed too.
Note please do not make too many changes in a single patch.
It is best to do refactoring like this in small steps making only 1 change at a time, that makes things a lot easier to review / to verify that there are no functional changes.
Regards,
Hans
Quoted 117 lines · On Tue, Oct 26, 2021 at 7:49 PM Mike Rapoport <[email protected]…
On Tue, Oct 26, 2021 at 07:12:53PM +0530, Kushal Kothari wrote:
> Refactor nested if-else to avoid deep indentations. There is no change
> in the logic of the new code, however, now it is simple because it gets
> rid of five unnecessary else conditionals and it combines nested if into
> single if-else-if. This refactor also leads to fix warning detected by
> checkpatch.pl <http://checkpatch.pl>:
> WARNING: Too many leading tabs - consider code refactoring
>
> Signed-off-by: Kushal Kothari <[email protected] <mailto:[email protected]>>
> ---
>
> Changes in v2: Fix the bug of not handling properly the else logic
> when p is not null in else-if. Also, reword the subject line and break
> it up at 72 columns.
>
> drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 69 ++++++++-----------
> 1 file changed, 29 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> index 0f82f5031c43..267d853b1514 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
> @@ -1192,50 +1192,39 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
> p = pframe + WLAN_HDR_A3_LEN + ie_offset; ie_len = 0;
> for (;;) {
> p = rtw_get_ie(p, WLAN_EID_VENDOR_SPECIFIC, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
> - if (p) {
> - if (!memcmp(p+2, WMM_IE, 6)) {
> -
> - pstat->flags |= WLAN_STA_WME;
> -
> - pstat->qos_option = 1;
> - pstat->qos_info = *(p+8);
> -
> - pstat->max_sp_len = (pstat->qos_info>>5)&0x3;
> -
> - if ((pstat->qos_info&0xf) != 0xf)
> - pstat->has_legacy_ac = true;
> - else
> - pstat->has_legacy_ac = false;
> -
> - if (pstat->qos_info&0xf) {
> - if (pstat->qos_info&BIT(0))
> - pstat->uapsd_vo = BIT(0)|BIT(1);
> - else
> - pstat->uapsd_vo = 0;
> -
> - if (pstat->qos_info&BIT(1))
> - pstat->uapsd_vi = BIT(0)|BIT(1);
> - else
> - pstat->uapsd_vi = 0;
> -
> - if (pstat->qos_info&BIT(2))
> - pstat->uapsd_bk = BIT(0)|BIT(1);
> - else
> - pstat->uapsd_bk = 0;
> -
> - if (pstat->qos_info&BIT(3))
> - pstat->uapsd_be = BIT(0)|BIT(1);
> - else
> - pstat->uapsd_be = 0;
> -
> - }
> -
> - break;
> + if (p && memcmp(p+2, WMM_IE, 6)) {
> + p = p + ie_len + 2;
> + } else if (p && !memcmp(p+2, WMM_IE, 6)) {
> + pstat->flags |= WLAN_STA_WME;
> + pstat->qos_option = 1;
> + pstat->qos_info = *(p+8);
> + pstat->max_sp_len = (pstat->qos_info>>5)&0x3;
> +
> + pstat->has_legacy_ac = false;
> + if ((pstat->qos_info&0xf) != 0xf)
> + pstat->has_legacy_ac = true;
> +
> + if (pstat->qos_info&0xf) {
> + pstat->uapsd_vo = 0;
This variable and other variables below are set to 0 just before the loop,
so the initialization here can be removed.
> + if (pstat->qos_info&BIT(0))
> + pstat->uapsd_vo = BIT(0)|BIT(1);
> +
> + pstat->uapsd_vi = 0;
> + if (pstat->qos_info&BIT(1))
> + pstat->uapsd_vi = BIT(0)|BIT(1);
> +
> + pstat->uapsd_bk = 0;
> + if (pstat->qos_info&BIT(2))
> + pstat->uapsd_bk = BIT(0)|BIT(1);
> +
> + pstat->uapsd_be = 0;
> + if (pstat->qos_info&BIT(3))
> + pstat->uapsd_be = BIT(0)|BIT(1);
> }
> + break;
> } else {
> break;
> }
> - p = p + ie_len + 2;
> }
> }
>
> --
> 2.25.1
>
--
Sincerely yours,
Mike.