staging: r8188eu: refactor rtw_is_cckrates_included()
PATCH v2 1/4 staging: r8188eu: refactor rtw_is_cckrates_included()
Refactor function rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.
---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.
drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +4 -5
@@ -70,14 +70,13 @@ int rtw_get_bit_value_from_ieee_value(u8 val)uint rtw_is_cckrates_included (u8 *rate) { -u32 i =0 ; +u8 r; -while (rate[i] !=0 ) { -if ((((rate[i]) &0x7f ) ==2 ) || (((rate[i]) &0x7f ) ==4 ) || - (((rate[i]) &0x7f ) ==11 ) || (((rate[i]) &0x7f ) ==22 )) +while ((r = *rate++ &0x7f )) { +if (r ==2 || r ==4 || r ==11 || r ==22 )return true; - i++; } +return false; }
Signature · 1 line
2.32.0
PATCH v2 2/4 staging: r8188eu: convert rtw_is_cckrates_included() to bool
Function rtw_is_cckrates_included() returns boolean values. Change the return type to bool to reflect this.
---
v1 -> v2
Rewritten to apply with v2 of patch 1/4.
drivers/staging/r8188eu/core/rtw_ieee80211.c | 2 +- drivers/staging/r8188eu/include/ieee80211.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +1 -1
@@ -68,7 +68,7 @@ int rtw_get_bit_value_from_ieee_value(u8 val)return 0 ; } -uint rtw_is_cckrates_included (u8 *rate) +bool rtw_is_cckrates_included (u8 *rate) {u8 r;
drivers/staging/r8188eu/include/ieee80211.h +1 -1
@@ -1206,7 +1206,7 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv);int rtw_get_bit_value_from_ieee_value (u8 val); -uint rtw_is_cckrates_included (u8 *rate); +bool rtw_is_cckrates_included (u8 *rate);uint rtw_is_cckratesonly_included (u8 *rate);
Signature · 1 line
2.32.0
Re: [PATCH v2 2/4] staging: r8188eu: convert rtw_is_cckrates_included() to bool
Quoted 7 lines · CEST Michael Straube
Function
rtw_is_cckrates_included()returns boolean values. Change the return type to bool to reflect this.Signed-off-by Michael Straube <[email protected]>---
v1 -> v2
Rewritten to apply with v2 of patch 1/4.
Thanks,
Fabio
PATCH v2 3/4 staging: r8188eu: refactor rtw_is_cckratesonly_included()
In reply to Michael StraubeRefactor function rtw_is_cckratesonly_included(). Improves readability and slightly reduces object file size.
---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.
drivers/staging/r8188eu/core/rtw_ieee80211.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +3 -5
@@ -82,13 +82,11 @@ bool rtw_is_cckrates_included(u8 *rate)uint rtw_is_cckratesonly_included (u8 *rate) { -u32 i =0 ; +u8 r; -while (rate[i] !=0 ) { -if ((((rate[i]) &0x7f ) !=2 ) && (((rate[i]) &0x7f ) !=4 ) && - (((rate[i]) &0x7f ) !=11 ) && (((rate[i]) &0x7f ) !=22 )) +while ((r = *rate++ &0x7f )) { +if (r !=2 && r !=4 && r !=11 && r !=22 )return false; - i++; }return true;
Signature · 1 line
2.32.0
Re: [PATCH v2 3/4] staging: r8188eu: refactor rtw_is_cckratesonly_included()
Quoted 10 lines · CEST Michael Straube
Refactor function
rtw_is_cckratesonly_included(). Improves readability and slightly reduces object file size.Signed-off-by Michael Straube <[email protected]>---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.drivers/staging/r8188eu/core/rtw_ieee80211.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
Thanks,
Fabio
PATCH v2 4/4 staging: r8188eu: convert rtw_is_cckratesonly_included() to bool
In reply to Michael StraubeFunction rtw_is_cckratesonly_included() returns boolean values. Change the return type to bool to reflect this.
---
v1 -> v2
Rewritten to apply with v2 of patch 3/4.
drivers/staging/r8188eu/core/rtw_ieee80211.c | 2 +- drivers/staging/r8188eu/include/ieee80211.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +1 -1
@@ -80,7 +80,7 @@ bool rtw_is_cckrates_included(u8 *rate)return false; } -uint rtw_is_cckratesonly_included (u8 *rate) +bool rtw_is_cckratesonly_included (u8 *rate) {u8 r;
drivers/staging/r8188eu/include/ieee80211.h +1 -2
@@ -1207,8 +1207,7 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv);int rtw_get_bit_value_from_ieee_value (u8 val);bool rtw_is_cckrates_included (u8 *rate); - -uint rtw_is_cckratesonly_included (u8 *rate); +bool rtw_is_cckratesonly_included (u8 *rate);int rtw_check_network_type (unsigned char *rate,int ratelen,int channel);
Signature · 1 line
2.32.0
Re: [PATCH v2 4/4] staging: r8188eu: convert rtw_is_cckratesonly_included() to bool
Quoted 11 lines · CEST Michael Straube
Function
rtw_is_cckratesonly_included()returns boolean values. Change the return type to bool to reflect this.Signed-off-by Michael Straube <[email protected]>---
v1 -> v2
Rewritten to apply with v2 of patch 3/4.drivers/staging/r8188eu/core/rtw_ieee80211.c | 2 +- drivers/staging/r8188eu/include/ieee80211.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)
Thanks,
Fabio
Quoted 11 lines · CEST Michael Straube
Refactor function
rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.Signed-off-by Michael Straube <[email protected]>---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Thanks for redoing the series as suggested by Joe Perches. This is a perfect case where conciseness and readability don't clash and instead the former enhances the latter.
Nice work, although you chose to not take Joe's suggestion about making a helper inline function. That would have been perfect, but I think it is a minor issue. So...
Regards,
Fabio
P.S.: If I were you, I'd have provided a cover letter that would have helped the readers to immediately understand the purpose of the entire series. I'm not sure whether or not the above-mentioned cover is a strict requirement.
Quoted 2 lines
(quoted diff) +0
-0
b/drivers/staging/r8188eu/core/rtw_ieee80211.cindex0c7231cefdda..
964255a8c778 100644
drivers/staging/r8188eu/core/rtw_ieee80211.c int rtw_get_bit_value_from_ieee_value(u8 val) · line 76
Quoted 11 lines
drivers/staging/r8188eu/core/rtw_ieee80211.c +1
-3@@ -70,14 +70,13 @@ int rtw_get_bit_value_from_ieee_value(u8 val)uint rtw_is_cckrates_included (u8 *rate) { -u32 i =0 ; +u8 r; -while (rate[i] !=0 ) { - if ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f)
== 4) ||
drivers/staging/r8188eu/core/rtw_ieee80211.c int rtw_get_bit_value_from_ieee_value(u8 val) · line 77
Quoted 1 line
drivers/staging/r8188eu/core/rtw_ieee80211.c +0
-1- (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f)
== 22))
Quoted 8 lines
drivers/staging/r8188eu/core/rtw_ieee80211.c +3
-1+while ((r = *rate++ &0x7f )) { +if (r ==2 || r ==4 || r ==11 || r ==22 )return true; - i++; } +return false; }
Quoted 9 lines · Fabio M. De Francesco
Quoted 8 lines · CEST Michael Straube
Refactor function
rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.Signed-off-by Michael Straube <[email protected]>---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.
Quoted 7 lines
Quoted 3 lines
drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)Thanks for redoing the series as suggested by Joe Perches. This is a perfect case where conciseness and readability don't clash and instead the former enhances the latter.
Perhaps do the whole thing in one go (moving the & 0x7f into the helper avoids an early loop exit defect when the rate being indexed is 0x80)
--- drivers/staging/r8188eu/core/rtw_ieee80211.c | 33 +++++++++++++++------------- drivers/staging/r8188eu/include/ieee80211.h | 5 ++--- drivers/staging/r8188eu/os_dep/ioctl_linux.c | 4 ++-- 3 files changed, 22 insertions(+), 20 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +18 -15
@@ -68,28 +68,31 @@ int rtw_get_bit_value_from_ieee_value(u8 val)return 0 ; } -uint rtw_is_cckrates_included (u8 *rate) +static bool rtw_is_cckrate (u8 rate) { -u32 i =0 ; + rate &=0x7f ; +return rate ==2 || rate ==4 || rate ==11 || rate ==22 ; +} + +bool rtw_is_cckrates_included (u8 *rate) +{ +u8 r; -while (rate[i] !=0 ) { -if ((((rate[i]) &0x7f ) ==2 ) || (((rate[i]) &0x7f ) ==4 ) || - (((rate[i]) &0x7f ) ==11 ) || (((rate[i]) &0x7f ) ==22 )) +while ((r = *rate++)) { +if (rtw_is_cckrate (r))return true; - i++; } +return false; } -uint rtw_is_cckratesonly_included (u8 *rate) +bool rtw_is_cckratesonly_included (u8 *rate) { -u32 i =0 ; +u8 r; -while (rate[i] !=0 ) { -if ((((rate[i]) &0x7f ) !=2 ) && (((rate[i]) &0x7f ) !=4 ) && - (((rate[i]) &0x7f ) !=11 ) && (((rate[i]) &0x7f ) !=22 )) +while ((r = *rate++)) { +if (!rtw_is_cckrate (r))return false; - i++; }return true;
@@ -98,14 +101,14 @@ uint rtw_is_cckratesonly_included(u8 *rate)int rtw_check_network_type (unsigned char *rate,int ratelen,int channel) {if (channel >14 ) { -if ((rtw_is_cckrates_included (rate)) == true) +if ((rtw_is_cckrates_included (rate)))return WIRELESS_INVALID ;else return WIRELESS_11A ; }else {/* could be pure B, pure G, or B/G */ -if ((rtw_is_cckratesonly_included (rate)) == true) +if ((rtw_is_cckratesonly_included (rate)))return WIRELESS_11B ; -else if ((rtw_is_cckrates_included (rate)) == true) +else if ((rtw_is_cckrates_included (rate)))return WIRELESS_11BG ;else return WIRELESS_11G ;
drivers/staging/r8188eu/include/ieee80211.h +2 -3
@@ -1225,9 +1225,8 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv);int rtw_get_bit_value_from_ieee_value (u8 val); -uint rtw_is_cckrates_included (u8 *rate); - -uint rtw_is_cckratesonly_included (u8 *rate); +bool rtw_is_cckrates_included (u8 *rate); +bool rtw_is_cckratesonly_included (u8 *rate);int rtw_check_network_type (unsigned char *rate,int ratelen,int channel);
drivers/staging/r8188eu/os_dep/ioctl_linux.c +2 -2
@@ -784,12 +784,12 @@ static int rtw_wx_get_name(struct net_device *dev, prates = &pcur_bss->SupportedRates; -if (rtw_is_cckratesonly_included ((u8 *)prates) == true) { +if (rtw_is_cckratesonly_included ((u8 *)prates)) {if (ht_cap)snprintf (wrqu->name,IFNAMSIZ ,"IEEE 802.11bn" );else snprintf (wrqu->name,IFNAMSIZ ,"IEEE 802.11b" ); - }else if ((rtw_is_cckrates_included ((u8 *)prates)) == true) { + }else if ((rtw_is_cckrates_included ((u8 *)prates))) {if (ht_cap)snprintf (wrqu->name,IFNAMSIZ ,"IEEE 802.11bgn" );else
Quoted 14 lines · Joe Perches
Quoted 13 lines · Fabio M. De Francesco
Quoted 11 lines · CEST Michael Straube
Refactor function
rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.Signed-off-by Michael Straube <[email protected]>---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 3 lines
Thanks for redoing the series as suggested by Joe Perches. This is a perfect case where conciseness and readability don't clash and instead the former enhances the latter.
Perhaps do the whole thing in one go (moving the &
0x7finto the helper avoids an early loop exit defect when the rate being indexed is0x80)
I will send v3 with your suggestions. The comparsions to boolean ( ... == true ) will be addressed in a separate series that cleans up comparsions to true/false in all files.
Regards,
Michael
Quoted 14 lines · Joe Perches
Quoted 13 lines · Fabio M. De Francesco
Quoted 11 lines · CEST Michael Straube
Refactor function
rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.Signed-off-by Michael Straube <[email protected]>---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 3 lines
Thanks for redoing the series as suggested by Joe Perches. This is a perfect case where conciseness and readability don't clash and instead the former enhances the latter.
Perhaps do the whole thing in one go (moving the &
0x7finto the helper avoids an early loop exit defect when the rate being indexed is0x80)
I have sent a new patch that does the refactoring in one go, so this series is obsolete now. ;)
Regards,
Michael