All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8723bs: simplify control flow
@ 2022-04-01 11:46 Sevinj Aghayeva
  2022-04-01 21:34 ` Ira Weiny
  0 siblings, 1 reply; 8+ messages in thread
From: Sevinj Aghayeva @ 2022-04-01 11:46 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy

The function iterates an index from 0 to NUM_PMKID_CACHE and returns
the first index for which the condition is true. If no such index is
found, the function returns -1. Current code has a complex control
flow that obfuscates this simple task. Replace it with a loop.

Also, given the shortened function body, replace the long variable
name psecuritypriv with a short variable name p.

Reported by checkpatch:

WARNING: else is not generally useful after a break or return

Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
---
 drivers/staging/rtl8723bs/core/rtw_mlme.c | 28 ++++++-----------------
 1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
index d5bb3a5bd2fb..3eacf8f9d236 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
@@ -2036,28 +2036,14 @@ int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_
 
 static int SecIsInPMKIDList(struct adapter *Adapter, u8 *bssid)
 {
-	struct security_priv *psecuritypriv = &Adapter->securitypriv;
-	int i = 0;
-
-	do {
-		if ((psecuritypriv->PMKIDList[i].bUsed) &&
-				(!memcmp(psecuritypriv->PMKIDList[i].Bssid, bssid, ETH_ALEN))) {
-			break;
-		} else {
-			i++;
-			/* continue; */
-		}
-
-	} while (i < NUM_PMKID_CACHE);
-
-	if (i == NUM_PMKID_CACHE) {
-		i = -1;/*  Could not find. */
-	} else {
-		/*  There is one Pre-Authentication Key for the specific BSSID. */
-	}
-
-	return i;
+	struct security_priv *p = &Adapter->securitypriv;
+	int i;
 
+	for (i = 0; i < NUM_PMKID_CACHE; i++)
+		if ((p->PMKIDList[i].bUsed) &&
+				(!memcmp(p->PMKIDList[i].Bssid, bssid, ETH_ALEN)))
+			return i;
+	return -1;
 }
 
 /*  */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] staging: rtl8723bs: simplify control flow
  2022-04-01 11:46 [PATCH] staging: rtl8723bs: simplify control flow Sevinj Aghayeva
@ 2022-04-01 21:34 ` Ira Weiny
  2022-04-01 22:46   ` Sevinj Aghayeva
  0 siblings, 1 reply; 8+ messages in thread
From: Ira Weiny @ 2022-04-01 21:34 UTC (permalink / raw)
  To: Sevinj Aghayeva
  Cc: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy

On Fri, Apr 01, 2022 at 07:46:35AM -0400, Sevinj Aghayeva wrote:
> The function iterates an index from 0 to NUM_PMKID_CACHE and returns
> the first index for which the condition is true. If no such index is
> found, the function returns -1. Current code has a complex control
> flow that obfuscates this simple task. Replace it with a loop.
> 
> Also, given the shortened function body, replace the long variable
> name psecuritypriv with a short variable name p.
> 
> Reported by checkpatch:
> 
> WARNING: else is not generally useful after a break or return
> 
> Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>

Wow!  Nice find!  This is a huge clean up.  Extra kudos recognizing that it is
not just the else statement which is broken here!

The only issue for the patch is that I don't see any maintainer emailed?
However, I don't see a maintainer listed in the MAINTAINERS file so ...

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> ---
>  drivers/staging/rtl8723bs/core/rtw_mlme.c | 28 ++++++-----------------
>  1 file changed, 7 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
> index d5bb3a5bd2fb..3eacf8f9d236 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
> @@ -2036,28 +2036,14 @@ int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_
>  
>  static int SecIsInPMKIDList(struct adapter *Adapter, u8 *bssid)
>  {
> -	struct security_priv *psecuritypriv = &Adapter->securitypriv;
> -	int i = 0;
> -
> -	do {
> -		if ((psecuritypriv->PMKIDList[i].bUsed) &&
> -				(!memcmp(psecuritypriv->PMKIDList[i].Bssid, bssid, ETH_ALEN))) {
> -			break;
> -		} else {
> -			i++;
> -			/* continue; */
> -		}
> -
> -	} while (i < NUM_PMKID_CACHE);
> -
> -	if (i == NUM_PMKID_CACHE) {
> -		i = -1;/*  Could not find. */
> -	} else {
> -		/*  There is one Pre-Authentication Key for the specific BSSID. */
> -	}
> -
> -	return i;
> +	struct security_priv *p = &Adapter->securitypriv;
> +	int i;
>  
> +	for (i = 0; i < NUM_PMKID_CACHE; i++)
> +		if ((p->PMKIDList[i].bUsed) &&
> +				(!memcmp(p->PMKIDList[i].Bssid, bssid, ETH_ALEN)))
> +			return i;
> +	return -1;
>  }
>  
>  /*  */
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] staging: rtl8723bs: simplify control flow
  2022-04-01 21:34 ` Ira Weiny
@ 2022-04-01 22:46   ` Sevinj Aghayeva
  2022-04-02  9:13     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 8+ messages in thread
From: Sevinj Aghayeva @ 2022-04-01 22:46 UTC (permalink / raw)
  To: Ira Weiny; +Cc: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy

On Fri, Apr 01, 2022 at 02:34:04PM -0700, Ira Weiny wrote:
> On Fri, Apr 01, 2022 at 07:46:35AM -0400, Sevinj Aghayeva wrote:
> > The function iterates an index from 0 to NUM_PMKID_CACHE and returns
> > the first index for which the condition is true. If no such index is
> > found, the function returns -1. Current code has a complex control
> > flow that obfuscates this simple task. Replace it with a loop.
> > 
> > Also, given the shortened function body, replace the long variable
> > name psecuritypriv with a short variable name p.
> > 
> > Reported by checkpatch:
> > 
> > WARNING: else is not generally useful after a break or return
> > 
> > Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
> 
> Wow!  Nice find!  This is a huge clean up.  Extra kudos recognizing that it is
> not just the else statement which is broken here!

Thanks! It took me a while to realize what this loop is doing.

> The only issue for the patch is that I don't see any maintainer emailed?
> However, I don't see a maintainer listed in the MAINTAINERS file so ...
> 
> Reviewed-by: Ira Weiny <ira.weiny@intel.com>

Thanks for the review!

Greg, please do not apply this yet. After I sent out the patch, I
noticed the comment at the top of the function:

/*  Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) */

So I did a git grep to find the original function and fix it as well,
and it looks like there are three copies of the same function in
different files:

$ git grep IsInPreAuthKeyList
r8188eu/core/rtw_mlme.c:/*  Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) */
rtl8712/rtl871x_mlme.c: * Ported from 8185: IsInPreAuthKeyList().
rtl8723bs/core/rtw_mlme.c:/*  Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) */

I will later send a v2 patch that replaces all of them.

Thanks

> > ---
> >  drivers/staging/rtl8723bs/core/rtw_mlme.c | 28 ++++++-----------------
> >  1 file changed, 7 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
> > index d5bb3a5bd2fb..3eacf8f9d236 100644
> > --- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
> > +++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
> > @@ -2036,28 +2036,14 @@ int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_
> >  
> >  static int SecIsInPMKIDList(struct adapter *Adapter, u8 *bssid)
> >  {
> > -	struct security_priv *psecuritypriv = &Adapter->securitypriv;
> > -	int i = 0;
> > -
> > -	do {
> > -		if ((psecuritypriv->PMKIDList[i].bUsed) &&
> > -				(!memcmp(psecuritypriv->PMKIDList[i].Bssid, bssid, ETH_ALEN))) {
> > -			break;
> > -		} else {
> > -			i++;
> > -			/* continue; */
> > -		}
> > -
> > -	} while (i < NUM_PMKID_CACHE);
> > -
> > -	if (i == NUM_PMKID_CACHE) {
> > -		i = -1;/*  Could not find. */
> > -	} else {
> > -		/*  There is one Pre-Authentication Key for the specific BSSID. */
> > -	}
> > -
> > -	return i;
> > +	struct security_priv *p = &Adapter->securitypriv;
> > +	int i;
> >  
> > +	for (i = 0; i < NUM_PMKID_CACHE; i++)
> > +		if ((p->PMKIDList[i].bUsed) &&
> > +				(!memcmp(p->PMKIDList[i].Bssid, bssid, ETH_ALEN)))
> > +			return i;
> > +	return -1;
> >  }
> >  
> >  /*  */
> > -- 
> > 2.25.1
> > 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] staging: rtl8723bs: simplify control flow
  2022-04-01 22:46   ` Sevinj Aghayeva
@ 2022-04-02  9:13     ` Greg Kroah-Hartman
  2022-04-03 13:50       ` Sevinj Aghayeva
  0 siblings, 1 reply; 8+ messages in thread
From: Greg Kroah-Hartman @ 2022-04-02  9:13 UTC (permalink / raw)
  To: Sevinj Aghayeva; +Cc: Ira Weiny, linux-staging, linux-kernel, outreachy

On Fri, Apr 01, 2022 at 06:46:19PM -0400, Sevinj Aghayeva wrote:
> On Fri, Apr 01, 2022 at 02:34:04PM -0700, Ira Weiny wrote:
> > On Fri, Apr 01, 2022 at 07:46:35AM -0400, Sevinj Aghayeva wrote:
> > > The function iterates an index from 0 to NUM_PMKID_CACHE and returns
> > > the first index for which the condition is true. If no such index is
> > > found, the function returns -1. Current code has a complex control
> > > flow that obfuscates this simple task. Replace it with a loop.
> > > 
> > > Also, given the shortened function body, replace the long variable
> > > name psecuritypriv with a short variable name p.
> > > 
> > > Reported by checkpatch:
> > > 
> > > WARNING: else is not generally useful after a break or return
> > > 
> > > Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
> > 
> > Wow!  Nice find!  This is a huge clean up.  Extra kudos recognizing that it is
> > not just the else statement which is broken here!
> 
> Thanks! It took me a while to realize what this loop is doing.
> 
> > The only issue for the patch is that I don't see any maintainer emailed?
> > However, I don't see a maintainer listed in the MAINTAINERS file so ...
> > 
> > Reviewed-by: Ira Weiny <ira.weiny@intel.com>
> 
> Thanks for the review!
> 
> Greg, please do not apply this yet. After I sent out the patch, I
> noticed the comment at the top of the function:
> 
> /*  Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) */
> 
> So I did a git grep to find the original function and fix it as well,
> and it looks like there are three copies of the same function in
> different files:
> 
> $ git grep IsInPreAuthKeyList
> r8188eu/core/rtw_mlme.c:/*  Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) */
> rtl8712/rtl871x_mlme.c: * Ported from 8185: IsInPreAuthKeyList().
> rtl8723bs/core/rtw_mlme.c:/*  Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) */
> 
> I will later send a v2 patch that replaces all of them.

No, please do one patch per driver.  These are all different drivers
(cut/pasted from some original source), so this patch is fine as-is.
You can make 2 other patches as well for the other drivers.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] staging: rtl8723bs: simplify control flow
  2022-04-02  9:13     ` Greg Kroah-Hartman
@ 2022-04-03 13:50       ` Sevinj Aghayeva
  0 siblings, 0 replies; 8+ messages in thread
From: Sevinj Aghayeva @ 2022-04-03 13:50 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Ira Weiny, linux-staging, linux-kernel, outreachy

On Sat, Apr 2, 2022 at 5:13 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Fri, Apr 01, 2022 at 06:46:19PM -0400, Sevinj Aghayeva wrote:
> > On Fri, Apr 01, 2022 at 02:34:04PM -0700, Ira Weiny wrote:
> > > On Fri, Apr 01, 2022 at 07:46:35AM -0400, Sevinj Aghayeva wrote:
> > > > The function iterates an index from 0 to NUM_PMKID_CACHE and returns
> > > > the first index for which the condition is true. If no such index is
> > > > found, the function returns -1. Current code has a complex control
> > > > flow that obfuscates this simple task. Replace it with a loop.
> > > >
> > > > Also, given the shortened function body, replace the long variable
> > > > name psecuritypriv with a short variable name p.
> > > >
> > > > Reported by checkpatch:
> > > >
> > > > WARNING: else is not generally useful after a break or return
> > > >
> > > > Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
> > >
> > > Wow!  Nice find!  This is a huge clean up.  Extra kudos recognizing that it is
> > > not just the else statement which is broken here!
> >
> > Thanks! It took me a while to realize what this loop is doing.
> >
> > > The only issue for the patch is that I don't see any maintainer emailed?
> > > However, I don't see a maintainer listed in the MAINTAINERS file so ...
> > >
> > > Reviewed-by: Ira Weiny <ira.weiny@intel.com>
> >
> > Thanks for the review!
> >
> > Greg, please do not apply this yet. After I sent out the patch, I
> > noticed the comment at the top of the function:
> >
> > /*  Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) */
> >
> > So I did a git grep to find the original function and fix it as well,
> > and it looks like there are three copies of the same function in
> > different files:
> >
> > $ git grep IsInPreAuthKeyList
> > r8188eu/core/rtw_mlme.c:/*  Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) */
> > rtl8712/rtl871x_mlme.c: * Ported from 8185: IsInPreAuthKeyList().
> > rtl8723bs/core/rtw_mlme.c:/*  Ported from 8185: IsInPreAuthKeyList(). (Renamed from SecIsInPreAuthKeyList(), 2006-10-13.) */
> >
> > I will later send a v2 patch that replaces all of them.
>
> No, please do one patch per driver.  These are all different drivers
> (cut/pasted from some original source), so this patch is fine as-is.
> You can make 2 other patches as well for the other drivers.

Sure, will send two more patches.

Thanks

>
> thanks,
>
> greg k-h



-- 

Sevinj.Aghayeva

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] staging: rtl8723bs: simplify control flow
       [not found]   ` <CAMWRUK6FaOC1+3ZP+af7uSyfAHjZ3KWwNqM1GjRYth+OyA-8EQ@mail.gmail.com>
@ 2022-04-13  3:01     ` Sevinj Aghayeva
  0 siblings, 0 replies; 8+ messages in thread
From: Sevinj Aghayeva @ 2022-04-13  3:01 UTC (permalink / raw)
  To: Ira Weiny
  Cc: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy linux kernel

[Resending again in plain-text mode.]


On Tue, Apr 12, 2022 at 10:59 PM Sevinj Aghayeva
<sevinj.aghayeva@gmail.com> wrote:
>
>
>
> On Tue, Apr 12, 2022 at 7:48 PM Ira Weiny <ira.weiny@intel.com> wrote:
>>
>> On Sun, Apr 03, 2022 at 06:42:07PM -0400, Sevinj Aghayeva wrote:
>> > Checkpatch issues "WARNING: else is not generally useful after a break
>> > or return" for the following code:
>> >
>> > while (1) {
>> >       do_join_r = rtw_do_join(padapter);
>> >       if (do_join_r == _SUCCESS) {
>> >               break;
>> >       } else {
>> >               rtw_dec_to_roam(padapter);
>> >
>> >               if (rtw_to_roam(padapter) > 0) {
>> >                       continue;
>> >               } else {
>> >                       rtw_indicate_disconnect(padapter);
>> >                       break;
>> >               }
>> >       }
>> > }
>> >
>> > We simplify this code in multiple steps. First, we remove do_join_r
>>
>> I can't say how Greg would like to see a change like this but my gut says that
>> each of these steps should be a patch in a series...
>>
>> > variable because it is only used right after it is assigned. Second,
>> > we remove the unnecessary else statement right after break:
>> >
>> > while (1) {
>> >       if (rtw_do_join(padapter) == _SUCCESS)
>> >               break;
>> >       rtw_dec_to_roam(padapter);
>> >
>> >       if (rtw_to_roam(padapter) > 0) {
>> >               continue;
>> >       } else {
>> >               rtw_indicate_disconnect(padapter);
>> >               break;
>> >       }
>> > }
>> >
>> > Next, we move the call to rtw_do_join into the while test because the
>> > while will loop only until the call is successful:
>> >
>> > while (rtw_do_join(padapter) != _SUCCESS) {
>> >       rtw_dec_to_roam(padapter);
>> >       if (rtw_to_roam(padapter) > 0) {
>> >               continue;
>> >       } else {
>> >               rtw_indicate_disconnect(padapter);
>> >               break;
>> >       }
>> > }
>> >
>> > Finally, looking at the code above, it is clear that the code will
>> > break out of the loop if rtw_to_roam call is <= 0. Hence:
>> >
>> > while (rtw_do_join(padapter) != _SUCCESS) {
>> >       rtw_dec_to_roam(padapter);
>> >       if (rtw_to_roam(padapter) <= 0) {
>> >               rtw_indicate_disconnect(padapter);
>> >               break;
>> >       }
>> > }
>>
>> ...  that said, this commit message made reviewing the change much easier,
>> thanks.
>
>
> This has landed a week ago, but thanks for the review anyway!
>
>>
>> Did you submit a patch for the r8188eu driver too?  I just noticed it has a
>> similar loop in _rtw_roaming().
>
>
> Right, there is also another similar loop in the same file as well. I think I wasn't sure that this patch was going to get accepted since it was a big change, so I didn't fix the others before this one got it. In the meantime I hit slightly more than 10 cleanup patches and moved on to working with my mentors. But I can fix the other loops if you think I should do it.
>
>>
>> Reviewed-by: Ira Weiny <ira.weiny@intel.com>
>>
>> >
>> > Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
>> > ---
>> >  drivers/staging/rtl8723bs/core/rtw_mlme.c | 18 ++++--------------
>> >  1 file changed, 4 insertions(+), 14 deletions(-)
>> >
>> > diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
>> > index 3eacf8f9d236..a45df775d535 100644
>> > --- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
>> > +++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
>> > @@ -2594,30 +2594,20 @@ void _rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network)
>> >  {
>> >       struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
>> >       struct wlan_network *cur_network = &pmlmepriv->cur_network;
>> > -     int do_join_r;
>> >
>> >       if (rtw_to_roam(padapter) > 0) {
>> >               memcpy(&pmlmepriv->assoc_ssid, &cur_network->network.ssid, sizeof(struct ndis_802_11_ssid));
>> >
>> >               pmlmepriv->assoc_by_bssid = false;
>> >
>> > -             while (1) {
>> > -                     do_join_r = rtw_do_join(padapter);
>> > -                     if (do_join_r == _SUCCESS) {
>> > +             while (rtw_do_join(padapter) != _SUCCESS) {
>> > +                     rtw_dec_to_roam(padapter);
>> > +                     if (rtw_to_roam(padapter) <= 0) {
>> > +                             rtw_indicate_disconnect(padapter);
>> >                               break;
>> > -                     } else {
>> > -                             rtw_dec_to_roam(padapter);
>> > -
>> > -                             if (rtw_to_roam(padapter) > 0) {
>> > -                                     continue;
>> > -                             } else {
>> > -                                     rtw_indicate_disconnect(padapter);
>> > -                                     break;
>> > -                             }
>> >                       }
>> >               }
>> >       }
>> > -
>> >  }
>> >
>> >  signed int rtw_linked_check(struct adapter *padapter)
>> > --
>> > 2.25.1
>> >
>
>
>
> --
>
> Sevinj.Aghayeva



-- 

Sevinj.Aghayeva

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] staging: rtl8723bs: simplify control flow
  2022-04-03 22:42 Sevinj Aghayeva
@ 2022-04-12 23:48 ` Ira Weiny
       [not found]   ` <CAMWRUK6FaOC1+3ZP+af7uSyfAHjZ3KWwNqM1GjRYth+OyA-8EQ@mail.gmail.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Ira Weiny @ 2022-04-12 23:48 UTC (permalink / raw)
  To: Sevinj Aghayeva
  Cc: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy

On Sun, Apr 03, 2022 at 06:42:07PM -0400, Sevinj Aghayeva wrote:
> Checkpatch issues "WARNING: else is not generally useful after a break
> or return" for the following code:
> 
> while (1) {
> 	do_join_r = rtw_do_join(padapter);
> 	if (do_join_r == _SUCCESS) {
> 		break;
> 	} else {
> 		rtw_dec_to_roam(padapter);
> 
> 		if (rtw_to_roam(padapter) > 0) {
> 			continue;
> 		} else {
> 			rtw_indicate_disconnect(padapter);
> 			break;
> 		}
> 	}
> }
> 
> We simplify this code in multiple steps. First, we remove do_join_r

I can't say how Greg would like to see a change like this but my gut says that
each of these steps should be a patch in a series...

> variable because it is only used right after it is assigned. Second,
> we remove the unnecessary else statement right after break:
> 
> while (1) {
> 	if (rtw_do_join(padapter) == _SUCCESS)
> 		break;
> 	rtw_dec_to_roam(padapter);
> 
> 	if (rtw_to_roam(padapter) > 0) {
> 		continue;
> 	} else {
> 		rtw_indicate_disconnect(padapter);
> 		break;
> 	}
> }
> 
> Next, we move the call to rtw_do_join into the while test because the
> while will loop only until the call is successful:
> 
> while (rtw_do_join(padapter) != _SUCCESS) {
> 	rtw_dec_to_roam(padapter);
> 	if (rtw_to_roam(padapter) > 0) {
> 		continue;
> 	} else {
> 		rtw_indicate_disconnect(padapter);
> 		break;
> 	}
> }
> 
> Finally, looking at the code above, it is clear that the code will
> break out of the loop if rtw_to_roam call is <= 0. Hence:
> 
> while (rtw_do_join(padapter) != _SUCCESS) {
> 	rtw_dec_to_roam(padapter);
> 	if (rtw_to_roam(padapter) <= 0) {
> 		rtw_indicate_disconnect(padapter);
> 		break;
> 	}
> }

...  that said, this commit message made reviewing the change much easier,
thanks.

Did you submit a patch for the r8188eu driver too?  I just noticed it has a
similar loop in _rtw_roaming().

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> 
> Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
> ---
>  drivers/staging/rtl8723bs/core/rtw_mlme.c | 18 ++++--------------
>  1 file changed, 4 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
> index 3eacf8f9d236..a45df775d535 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
> @@ -2594,30 +2594,20 @@ void _rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network)
>  {
>  	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
>  	struct wlan_network *cur_network = &pmlmepriv->cur_network;
> -	int do_join_r;
>  
>  	if (rtw_to_roam(padapter) > 0) {
>  		memcpy(&pmlmepriv->assoc_ssid, &cur_network->network.ssid, sizeof(struct ndis_802_11_ssid));
>  
>  		pmlmepriv->assoc_by_bssid = false;
>  
> -		while (1) {
> -			do_join_r = rtw_do_join(padapter);
> -			if (do_join_r == _SUCCESS) {
> +		while (rtw_do_join(padapter) != _SUCCESS) {
> +			rtw_dec_to_roam(padapter);
> +			if (rtw_to_roam(padapter) <= 0) {
> +				rtw_indicate_disconnect(padapter);
>  				break;
> -			} else {
> -				rtw_dec_to_roam(padapter);
> -
> -				if (rtw_to_roam(padapter) > 0) {
> -					continue;
> -				} else {
> -					rtw_indicate_disconnect(padapter);
> -					break;
> -				}
>  			}
>  		}
>  	}
> -
>  }
>  
>  signed int rtw_linked_check(struct adapter *padapter)
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] staging: rtl8723bs: simplify control flow
@ 2022-04-03 22:42 Sevinj Aghayeva
  2022-04-12 23:48 ` Ira Weiny
  0 siblings, 1 reply; 8+ messages in thread
From: Sevinj Aghayeva @ 2022-04-03 22:42 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy

Checkpatch issues "WARNING: else is not generally useful after a break
or return" for the following code:

while (1) {
	do_join_r = rtw_do_join(padapter);
	if (do_join_r == _SUCCESS) {
		break;
	} else {
		rtw_dec_to_roam(padapter);

		if (rtw_to_roam(padapter) > 0) {
			continue;
		} else {
			rtw_indicate_disconnect(padapter);
			break;
		}
	}
}

We simplify this code in multiple steps. First, we remove do_join_r
variable because it is only used right after it is assigned. Second,
we remove the unnecessary else statement right after break:

while (1) {
	if (rtw_do_join(padapter) == _SUCCESS)
		break;
	rtw_dec_to_roam(padapter);

	if (rtw_to_roam(padapter) > 0) {
		continue;
	} else {
		rtw_indicate_disconnect(padapter);
		break;
	}
}

Next, we move the call to rtw_do_join into the while test because the
while will loop only until the call is successful:

while (rtw_do_join(padapter) != _SUCCESS) {
	rtw_dec_to_roam(padapter);
	if (rtw_to_roam(padapter) > 0) {
		continue;
	} else {
		rtw_indicate_disconnect(padapter);
		break;
	}
}

Finally, looking at the code above, it is clear that the code will
break out of the loop if rtw_to_roam call is <= 0. Hence:

while (rtw_do_join(padapter) != _SUCCESS) {
	rtw_dec_to_roam(padapter);
	if (rtw_to_roam(padapter) <= 0) {
		rtw_indicate_disconnect(padapter);
		break;
	}
}

Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
---
 drivers/staging/rtl8723bs/core/rtw_mlme.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c
index 3eacf8f9d236..a45df775d535 100644
--- a/drivers/staging/rtl8723bs/core/rtw_mlme.c
+++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c
@@ -2594,30 +2594,20 @@ void _rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network)
 {
 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 	struct wlan_network *cur_network = &pmlmepriv->cur_network;
-	int do_join_r;
 
 	if (rtw_to_roam(padapter) > 0) {
 		memcpy(&pmlmepriv->assoc_ssid, &cur_network->network.ssid, sizeof(struct ndis_802_11_ssid));
 
 		pmlmepriv->assoc_by_bssid = false;
 
-		while (1) {
-			do_join_r = rtw_do_join(padapter);
-			if (do_join_r == _SUCCESS) {
+		while (rtw_do_join(padapter) != _SUCCESS) {
+			rtw_dec_to_roam(padapter);
+			if (rtw_to_roam(padapter) <= 0) {
+				rtw_indicate_disconnect(padapter);
 				break;
-			} else {
-				rtw_dec_to_roam(padapter);
-
-				if (rtw_to_roam(padapter) > 0) {
-					continue;
-				} else {
-					rtw_indicate_disconnect(padapter);
-					break;
-				}
 			}
 		}
 	}
-
 }
 
 signed int rtw_linked_check(struct adapter *padapter)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-04-13  3:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 11:46 [PATCH] staging: rtl8723bs: simplify control flow Sevinj Aghayeva
2022-04-01 21:34 ` Ira Weiny
2022-04-01 22:46   ` Sevinj Aghayeva
2022-04-02  9:13     ` Greg Kroah-Hartman
2022-04-03 13:50       ` Sevinj Aghayeva
2022-04-03 22:42 Sevinj Aghayeva
2022-04-12 23:48 ` Ira Weiny
     [not found]   ` <CAMWRUK6FaOC1+3ZP+af7uSyfAHjZ3KWwNqM1GjRYth+OyA-8EQ@mail.gmail.com>
2022-04-13  3:01     ` Sevinj Aghayeva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.