staging: rtl8723bs: replace while with shorter for loop
PATCH 1/6 staging: rtl8723bs: replace while with shorter for loop
Simplify rtw_get_rateset_len() by replacing the while loop with a shorter for loop.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +3 -9
@@ -298,17 +298,11 @@ void rtw_set_supported_rate(u8 *SupportedRates, uint mode)uint rtw_get_rateset_len (u8 *rateset) { -uint i =0 ; +uint i; -while (1 ) { -if ((rateset[i]) ==0 ) -break ; - -if (i >12 ) +for (i =0 ; i <13 ; i++) +if (rateset[i] ==0 )break ; - - i++; - }return i; }
Signature · 1 line
2.18.0
PATCH 2/6 staging: rtl8723bs: replace tab with space
Replace tabs with spaces in some function definitions.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +3 -3
@@ -67,7 +67,7 @@ int rtw_get_bit_value_from_ieee_value(u8 val)return 0 ; } -uint rtw_is_cckrates_included (u8 *rate) +uint rtw_is_cckrates_included (u8 *rate) {u32 i =0 ;
@@ -81,7 +81,7 @@ uint rtw_is_cckrates_included(u8 *rate)return false; } -uint rtw_is_cckratesonly_included (u8 *rate) +uint rtw_is_cckratesonly_included (u8 *rate) {u32 i =0 ;
@@ -296,7 +296,7 @@ void rtw_set_supported_rate(u8 *SupportedRates, uint mode) } } -uint rtw_get_rateset_len (u8 *rateset) +uint rtw_get_rateset_len (u8 *rateset) {uint i;
Signature · 1 line
2.18.0
PATCH 3/6 staging: rtl8723bs: fix indentation
In reply to Michael StraubeRemove unrequired extra indentations.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +8 -8
@@ -69,16 +69,16 @@ int rtw_get_bit_value_from_ieee_value(u8 val)uint rtw_is_cckrates_included (u8 *rate) { -u32 i =0 ; +u32 i =0 ; -while (rate[i] !=0 ) { -if ((((rate[i]) &0x7f ) ==2 ) || (((rate[i]) &0x7f ) ==4 ) || - (((rate[i]) &0x7f ) ==11 ) || (((rate[i]) &0x7f ) ==22 )) -return true; - i++; - } +while (rate[i] !=0 ) { +if ((((rate[i]) &0x7f ) ==2 ) || (((rate[i]) &0x7f ) ==4 ) || + (((rate[i]) &0x7f ) ==11 ) || (((rate[i]) &0x7f ) ==22 )) +return true; + i++; + } -return false; +return false; }uint rtw_is_cckratesonly_included (u8 *rate)
Signature · 1 line
2.18.0
Re: [PATCH 3/6] staging: rtl8723bs: fix indentation
Quoted 1 line · Michael Straube
Remove unrequired extra indentations.
[]
drivers/staging/rtl8723bs/core/rtw_ieee80211.c
Quoted 1 line
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +0
-0
[]
Quoted 13 lines
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +1
-7@@ -69,16 +69,16 @@ int rtw_get_bit_value_from_ieee_value(u8 val)uint rtw_is_cckrates_included (u8 *rate) { -u32 i =0 ; +u32 i =0 ; -while (rate[i] !=0 ) { -if ((((rate[i]) &0x7f ) ==2 ) || (((rate[i]) &0x7f ) ==4 ) || - (((rate[i]) &0x7f ) ==11 ) || (((rate[i]) &0x7f ) ==22 )) -return true; - i++; - }
drivers/staging/rtl8723bs/core/rtw_ieee80211.c int rtw_get_bit_value_from_ieee_value(u8 val) · line 82
Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +7
-1+while (rate[i] !=0 ) { +if ((((rate[i]) &0x7f ) ==2 ) || (((rate[i]) &0x7f ) ==4 ) || + (((rate[i]) &0x7f ) ==11 ) || (((rate[i]) &0x7f ) ==22 )) +return true; + i++; + } -return false; +return false; }
Hi Michael.
Please try to improve the code for human readers and/or reduce overall object size over merely shutting up checkpatch style warnings.
For instance:
You could reduce object size a little by eliminating the multiple use of 0x7f and index and dereferencing the pointer instead.
$ size drivers/staging/rtl8723bs/core/rtw_ieee80211.o* text data bss dec hex filename 10085 76 0 10161 27b1 drivers/staging/rtl8723bs/core/rtw_ieee80211.o.new 10149 76 0 10225 27f1 drivers/staging/rtl8723bs/core/rtw_ieee80211.o.old
Something like:
uint rtw_is_cckrates_included(u8 *rate)
{
while (*rate) {
u8 r = *rate & 0x7f;
if (r == 2 || r == 4 || r == 11 || r == 22)
return true;
rate++;
}
return false;
}uint rtw_is_cckratesonly_included(u8 *rate)
{
while (*rate) {
u8 r = *rate & 0x7f;
if (r != 2 && r != 4 && r != 11 && r != 22)
return false;
rate++;
}
return true;
}Re: [PATCH 3/6] staging: rtl8723bs: fix indentation
Quoted 31 lines · Joe Perches
Quoted 1 line · Michael Straube
Remove unrequired extra indentations.
[]
drivers/staging/rtl8723bs/core/rtw_ieee80211.c
Quoted 1 line
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +0
-0[]
Quoted 13 lines
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +1
-7@@ -69,16 +69,16 @@ int rtw_get_bit_value_from_ieee_value(u8 val)uint rtw_is_cckrates_included (u8 *rate) { -u32 i =0 ; +u32 i =0 ; -while (rate[i] !=0 ) { -if ((((rate[i]) &0x7f ) ==2 ) || (((rate[i]) &0x7f ) ==4 ) || - (((rate[i]) &0x7f ) ==11 ) || (((rate[i]) &0x7f ) ==22 )) -return true; - i++; - }drivers/staging/rtl8723bs/core/rtw_ieee80211.c int rtw_get_bit_value_from_ieee_value(u8 val) · line 82
Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +7
-1+while (rate[i] !=0 ) { +if ((((rate[i]) &0x7f ) ==2 ) || (((rate[i]) &0x7f ) ==4 ) || + (((rate[i]) &0x7f ) ==11 ) || (((rate[i]) &0x7f ) ==22 )) +return true; + i++; + } -return false; +return false; }Hi Michael.
Quoted 4 lines
Please try to improve the code for human readers and/or reduce overall object size over merely shutting up checkpatch style warnings.
Hi Joe,
I agree that it's better to improve the code than just silence warnings.
Thanks for your advice.
Quoted 27 lines
For instance:
You could reduce object size a little by eliminating the multiple use of
0x7fand index and dereferencing the pointer instead.$ size drivers/staging/rtl8723bs/core/rtw_ieee80211.o* text data bss dec hex filename 10085 76 0 10161 27b1 drivers/staging/rtl8723bs/core/rtw_ieee80211.o.new 10149 76 0 10225 27f1 drivers/staging/rtl8723bs/core/rtw_ieee80211.o.oldSomething like:
uint
rtw_is_cckrates_included(u8 *rate){ while (*rate) { u8 r = *rate & 0x7f; if (r == 2 || r == 4 || r == 11 || r == 22) return true; rate++; } return false; }uint
rtw_is_cckratesonly_included(u8 *rate)
Quoted 12 lines
{
while (*rate) {
u8 r = *rate & 0x7f;
if (r != 2 && r != 4 && r != 11 && r != 22)
return false;
rate++;
}
return true;
}The patch has been added to staging-testing already. I will send patches with your suggestions the next days.
Thanks again.
Michael
Re: [PATCH 3/6] staging: rtl8723bs: fix indentation
Quoted 13 lines · Michael Straube
Quoted 12 lines · Joe Perches
On Sun, 2018-07-08 at 12:38 +0200, Michael Straube wrote:
uint
rtw_is_cckratesonly_included(u8 *rate)
{
while (*rate) {
u8 r = *rate &0x7f;if (r != 2 && r != 4 && r != 11 && r != 22) return false;
rate++;
}
Quoted 6 lines
Quoted 3 lines
return true;
}The patch has been added to staging-testing already. I will send patches with your suggestions the next days.
Would it be preferred to declare the variable at the functions beginning, or doesn't it matter regarding coding style?
uint rtw_is_cckratesonly_included(u8 *rate)
{
u8 r;
while (*rate) {
r = *rate & 0x7f;
...Best,
Michael
Re: [PATCH 3/6] staging: rtl8723bs: fix indentation
Quoted 18 lines · Michael Straube
Quoted 17 lines · Michael Straube
Quoted 15 lines · Joe Perches
On Sun, 2018-07-08 at 12:38 +0200, Michael Straube wrote:
uint
rtw_is_cckratesonly_included(u8 *rate){ while (*rate) { u8 r = *rate & 0x7f; if (r != 2 && r != 4 && r != 11 && r != 22) return false; rate++; } return true; }
Quoted 5 lines
Quoted 2 lines
The patch has been added to staging-testing already. I will send patches with your suggestions the next days.
Would it be preferred to declare the variable at the functions beginning, or doesn't it matter regarding coding style?
Not really.
It's generally preferred to have declarations in the nearest possible open brace to allow the compiler to reduce the overall stack space consumed by the function.
For example prefer:
int some_function(int arg, void *pointer)
{
if (arg == 1} {
struct foo a = *(struct foo *)pointer;
...
} else if (arg == 2) {
struct bar b = *(struct bar *)pointer;
...
}
}over
int some_function(int arg, void *pointer)
{
struct foo a;
struct bar b;
if (arg == 1} {
a = *(struct foo *)pointer;
...
} else if (arg == 2) {
b = *(struct bar *)pointer;
...
}
}as a and b could use the same stack in the first example but not the second.
Re: [PATCH 3/6] staging: rtl8723bs: fix indentation
Quoted 61 lines · Joe Perches
Quoted 18 lines · Michael Straube
Quoted 17 lines · Michael Straube
Quoted 15 lines · Joe Perches
On Sun, 2018-07-08 at 12:38 +0200, Michael Straube wrote:
uint
rtw_is_cckratesonly_included(u8 *rate){ while (*rate) { u8 r = *rate & 0x7f; if (r != 2 && r != 4 && r != 11 && r != 22) return false; rate++; } return true; }Quoted 5 lines
Quoted 2 lines
The patch has been added to staging-testing already. I will send patches with your suggestions the next days.
Would it be preferred to declare the variable at the functions beginning, or doesn't it matter regarding coding style?
Not really.
It's generally preferred to have declarations in the nearest possible open brace to allow the compiler to reduce the overall stack space consumed by the function.
For example prefer:
int
some_function(int arg, void *pointer){ if (arg == 1} { struct foo a = *(struct foo *)pointer; ... } else if (arg == 2) { struct bar b = *(struct bar *)pointer; ... } }over
int
some_function(int arg, void *pointer){ struct foo a; struct bar b;
if (arg == 1} { a = *(struct foo *)pointer; ... } else if (arg == 2) { b = *(struct bar *)pointer; ... } }
Quoted 3 lines
as a and b could use the same stack in the first example but not the second.
Ok, thanks for explaining.
Michael
PATCH 4/6 staging: rtl8723bs: remove blank lines
In reply to Michael StraubeRemove unrequired blank lines as reported by checkpatch.
--- .../staging/rtl8723bs/core/rtw_ieee80211.c | 31 ------------------- 1 file changed, 31 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +0 -31
@@ -53,11 +53,9 @@ static u8 WIFI_OFDMRATES[] = { IEEE80211_OFDM_RATE_54MB }; -int rtw_get_bit_value_from_ieee_value (u8 val) {unsigned char dot11_rate_table[] = {2 ,4 ,11 ,22 ,12 ,18 ,24 ,36 ,48 ,72 ,96 ,108 ,0 };/* last element must be zero!! */ -int i =0 ;while (dot11_rate_table[i] !=0 ) {if (dot11_rate_table[i] == val)
@@ -85,7 +83,6 @@ uint rtw_is_cckratesonly_included(u8 *rate) {u32 i =0 ; -while (rate[i] !=0 ) {if ((((rate[i]) &0x7f ) !=2 ) && (((rate[i]) &0x7f ) !=4 ) && (((rate[i]) &0x7f ) !=11 ) && (((rate[i]) &0x7f ) !=22 ))
@@ -111,7 +108,6 @@ int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)else return WIRELESS_11G ; } - } u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,
@@ -191,7 +187,6 @@ u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uuint cnt;u8 *target_ie =NULL ; -if (ielen) *ielen =0 ;
@@ -215,7 +210,6 @@ u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, u }else { cnt += in_ie[cnt+1 ]+2 ;/* goto next */ } - }return target_ie;
@@ -292,7 +286,6 @@ void rtw_set_supported_rate(u8 *SupportedRates, uint mode)memcpy (SupportedRates,WIFI_CCKRATES ,IEEE80211_CCK_RATE_LEN );memcpy (SupportedRates +IEEE80211_CCK_RATE_LEN ,WIFI_OFDMRATES ,IEEE80211_NUM_OFDM_RATESLEN );break ; - } }
@@ -363,7 +356,6 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv)/* DS parameter set */ ie =rtw_set_ie (ie, _DSSET_IE_,1 , (u8 *)&(pdev_network->Configuration.DSConfig), &sz); -/* IBSS Parameter Set */ ie =rtw_set_ie (ie, _IBSS_PARA_IE_,2 , (u8 *)&(pdev_network->Configuration.ATIMWindow), &sz);
@@ -398,10 +390,8 @@ unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit) pbuf =rtw_get_ie (pbuf, _WPA_IE_ID_, &len, limit_new);if (pbuf) { -/* check if oui matches... */ if (memcmp ((pbuf +2 ), wpa_oui_type,sizeof (wpa_oui_type))) { - goto check_next_ie; }
@@ -417,7 +407,6 @@ unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)return pbuf; }else { - *wpa_ie_len =0 ;return NULL ; }
@@ -430,20 +419,16 @@ unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)break ; pbuf += (2 + len); - } *wpa_ie_len =0 ;return NULL ; - }unsigned char *rtw_get_wpa2_ie (unsigned char *pie,int *rsn_ie_len,int limit) { -return rtw_get_ie (pie, _WPA2_IE_ID_, rsn_ie_len, limit); - }int rtw_get_wpa_cipher_suite (u8 *s)
@@ -478,7 +463,6 @@ int rtw_get_wpa2_cipher_suite(u8 *s)return 0 ; } -int rtw_parse_wpa_ie (u8 *wpa_ie,int wpa_ie_len,int *group_cipher,int *pairwise_cipher,int *is_8021x) {int i, ret = _SUCCESS;
@@ -491,7 +475,6 @@ int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwisreturn _FAIL; } -if ((*wpa_ie != _WPA_IE_ID_) || (*(wpa_ie+1 ) != (u8)(wpa_ie_len -2 )) || (memcmp (wpa_ie+2 ,RTW_WPA_OUI_TYPE ,WPA_SELECTOR_LEN ))) {return _FAIL;
@@ -502,10 +485,8 @@ int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwis pos +=8 ; left = wpa_ie_len -8 ; -/* group_cipher */ if (left >=WPA_SELECTOR_LEN ) { - *group_cipher =rtw_get_wpa_cipher_suite (pos); pos +=WPA_SELECTOR_LEN ;
@@ -517,7 +498,6 @@ int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwisreturn _FAIL; } -/* pairwise_cipher */ if (left >=2 ) {/* count = le16_to_cpu(*(u16*)pos); */
@@ -554,7 +534,6 @@ int rtw_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwis }return ret; - }int rtw_parse_wpa2_ie (u8 *rsn_ie,int rsn_ie_len,int *group_cipher,int *pairwise_cipher,int *is_8021x)
@@ -569,7 +548,6 @@ int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwireturn _FAIL; } -if ((*rsn_ie != _WPA2_IE_ID_) || (*(rsn_ie+1 ) != (u8)(rsn_ie_len -2 ))) {return _FAIL; }
@@ -580,7 +558,6 @@ int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwi/* group_cipher */ if (left >=RSN_SELECTOR_LEN ) { - *group_cipher =rtw_get_wpa2_cipher_suite (pos); pos +=RSN_SELECTOR_LEN ;
@@ -628,7 +605,6 @@ int rtw_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher, int *pairwi }return ret; - }/* ifdef CONFIG_WAPI_SUPPORT */
@@ -730,7 +706,6 @@ int rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, cnt += in_ie[cnt+1 ]+2 ;/* get next */ } } - }return (*rsn_len + *wpa_len);
@@ -795,7 +770,6 @@ u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen) }else { cnt += in_ie[cnt+1 ]+2 ;/* goto next */ } - }return wpsie_ptr;
@@ -848,7 +822,6 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_att }else { attr_ptr += attr_len;/* goto next */ } - }return target_attr_ptr;
@@ -981,7 +954,6 @@ static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen, }return 0 ; - }/**
@@ -1128,7 +1100,6 @@ ParseRes rtw_ieee802_11_parse_elems(u8 *start, uint len,return ParseFailed;return unknown ? ParseUnknown : ParseOK; - }void rtw_macaddr_cfg (struct device *dev,u8 *mac_addr)
@@ -1173,7 +1144,6 @@ static int rtw_get_cipher_info(struct wlan_network *pnetwork)if (pbuf && (wpa_ielen >0 )) {RT_TRACE (_module_rtl871x_mlme_c_, _drv_info_, ("rtw_get_cipher_info: wpa_ielen: %d" , wpa_ielen));if (_SUCCESS ==rtw_parse_wpa_ie (pbuf, wpa_ielen+2 , &group_cipher, &pairwise_cipher, &is8021x)) { - pnetwork->BcnInfo.pairwise_cipher = pairwise_cipher; pnetwork->BcnInfo.group_cipher = group_cipher; pnetwork->BcnInfo.is_8021x = is8021x;
@@ -1182,7 +1152,6 @@ static int rtw_get_cipher_info(struct wlan_network *pnetwork) ret = _SUCCESS; } }else { - pbuf =rtw_get_wpa2_ie (&pnetwork->network.IEs[12 ], &wpa_ielen, pnetwork->network.IELength-12 );if (pbuf && (wpa_ielen >0 )) {
Signature · 1 line
2.18.0
PATCH 5/6 staging: rtl8723bs: add missing blank lines
In reply to Michael StraubeAdd missing blank lines after declarations as reported by checkpatch.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +2 -0
@@ -57,6 +57,7 @@ int rtw_get_bit_value_from_ieee_value(u8 val) {unsigned char dot11_rate_table[] = {2 ,4 ,11 ,22 ,12 ,18 ,24 ,36 ,48 ,72 ,96 ,108 ,0 };/* last element must be zero!! */ int i =0 ; +while (dot11_rate_table[i] !=0 ) {if (dot11_rate_table[i] == val)return BIT (i);
@@ -1139,6 +1140,7 @@ static int rtw_get_cipher_info(struct wlan_network *pnetwork)unsigned char *pbuf;int group_cipher =0 , pairwise_cipher =0 , is8021x =0 ;int ret = _FAIL; + pbuf =rtw_get_wpa_ie (&pnetwork->network.IEs[12 ], &wpa_ielen, pnetwork->network.IELength-12 );if (pbuf && (wpa_ielen >0 )) {
Signature · 1 line
2.18.0
PATCH 6/6 staging: rtl8723bs: remove braces from single if statement
In reply to Michael StraubeRemove braces from single if statement to follow kernel coding style.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +1 -2
@@ -149,9 +149,8 @@ u8 *rtw_get_ie(u8 *pbuf, sint index, sint *len, sint limit)sint tmp, i;u8 *p; -if (limit <1 ) { +if (limit <1 )return NULL ; - } p = pbuf; i =0 ;
Signature · 1 line
2.18.0