On 2020-09-12 20:22, Joe Perches wrote:
On Sat, 2020-09-12 at 10:45 +0200, Michael Straube wrote:
Refactor cckrates_included() and cckratesonly_included() to simplify
the code and improve readability.

Signed-off-by: Michael Straube <straube.li...@gmail.com>
---
  drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c 
b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
index a5790a648a5b..4e0d86b2e2e0 100644
--- a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
@@ -56,11 +56,12 @@ static u8 rtw_basic_rate_ofdm[3] = {
int cckrates_included(unsigned char *rate, int ratelen)
  {
-       int     i;
+       int i;
for (i = 0; i < ratelen; i++) {
-               if  ((((rate[i]) & 0x7f) == 2)      || (((rate[i]) & 0x7f) == 
4) ||
-                    (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
+               u8 r = rate[i] & 0x7f;
+
+               if (r == 2 || r == 4 || r == 11 || r == 22)
                        return true;
        }
@@ -69,11 +70,12 @@ int cckrates_included(unsigned char *rate, int ratelen) int cckratesonly_included(unsigned char *rate, int ratelen)
  {
-       int     i;
+       int i;
for (i = 0; i < ratelen; i++) {
-               if  ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
-                    (((rate[i]) & 0x7f) != 11)  && (((rate[i]) & 0x7f) != 22))
+               u8 r = rate[i] & 0x7f;
+
+               if (r != 2 && r != 4 && r != 11 && r != 22)
                        return false;

It would be simpler to add and use an inline like:

static bool is_cckrate(unsigned char rate)
{
        rate &= 0x7f;
        return rate == 2 || rate == 4 || rate == 11 || rate == 22;
}

so these could be

bool cckrates_included(unsigned char *rate, int ratelen)
{
        int i;

        for (i = 0; i < ratelen; i++) {
                if (is_cckrate(rate[i])
                        return true;
        }

        return false;
}

bool cckratesonly_included(unsigned char *rate, int ratelen)
{
        int i;

        if (i <= 0)
                return false;

        for (i = 0; i < ratelen; i++) {
                if (!is_cckrate(rate[i])
                        return false;
        }

        return true;
}



I've just seen that there are already rtw_is_cckrates_included and 
rtw_is_cckratesonly_included
in rtw_ieee80211.c that can be used here.

I will send another series removing the functions from rtw_wlan_util.c and use 
the ones from
rtw_ieee80211.c.

So please don't merge this series, thanks.

Michael

_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

Reply via email to