public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	outreachy@lists.linux.dev
Subject: Re: [PATCH] staging: rtl8723bs: simplify control flow
Date: Tue, 12 Apr 2022 16:48:08 -0700	[thread overview]
Message-ID: <YlYPuIMr8mq66Lea@iweiny-desk3> (raw)
In-Reply-To: <20220403224207.GA397480@euclid>

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
> 

  reply	other threads:[~2022-04-12 23:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-03 22:42 [PATCH] staging: rtl8723bs: simplify control flow Sevinj Aghayeva
2022-04-12 23:48 ` Ira Weiny [this message]
     [not found]   ` <CAMWRUK6FaOC1+3ZP+af7uSyfAHjZ3KWwNqM1GjRYth+OyA-8EQ@mail.gmail.com>
2022-04-13  3:01     ` Sevinj Aghayeva
  -- strict thread matches above, loose matches on Subject: below --
2022-04-01 11:46 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YlYPuIMr8mq66Lea@iweiny-desk3 \
    --to=ira.weiny@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=outreachy@lists.linux.dev \
    --cc=sevinj.aghayeva@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox