* [PATCH v2] staging: r8188eu: simplify control flow
@ 2022-04-03 16:42 Sevinj Aghayeva
2022-04-04 2:46 ` Sevinj Aghayeva
0 siblings, 1 reply; 2+ messages in thread
From: Sevinj Aghayeva @ 2022-04-03 16:42 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>
---
v1 -> v2: Put the conditional in a single line to avoid checkpatch
complaint.
drivers/staging/r8188eu/core/rtw_mlme.c | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_mlme.c b/drivers/staging/r8188eu/core/rtw_mlme.c
index f94b1536a177..cddd8ab80236 100644
--- a/drivers/staging/r8188eu/core/rtw_mlme.c
+++ b/drivers/staging/r8188eu/core/rtw_mlme.c
@@ -1637,26 +1637,13 @@ 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);
+ struct security_priv *p = &Adapter->securitypriv;
+ int i;
- if (i == NUM_PMKID_CACHE) {
- i = -1;/* Could not find. */
- } else {
- /* There is one Pre-Authentication Key for the specific BSSID. */
- }
- return 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] 2+ messages in thread
* Re: [PATCH v2] staging: r8188eu: simplify control flow
2022-04-03 16:42 [PATCH v2] staging: r8188eu: simplify control flow Sevinj Aghayeva
@ 2022-04-04 2:46 ` Sevinj Aghayeva
0 siblings, 0 replies; 2+ messages in thread
From: Sevinj Aghayeva @ 2022-04-04 2:46 UTC (permalink / raw)
To: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy
Cc: Larry Finger, Phillip Potter
My apologies for forgetting to Cc the maintainers! Added them now.
On Sun, Apr 03, 2022 at 12:42:50PM -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>
> ---
>
> v1 -> v2: Put the conditional in a single line to avoid checkpatch
> complaint.
>
> drivers/staging/r8188eu/core/rtw_mlme.c | 25 ++++++-------------------
> 1 file changed, 6 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/core/rtw_mlme.c b/drivers/staging/r8188eu/core/rtw_mlme.c
> index f94b1536a177..cddd8ab80236 100644
> --- a/drivers/staging/r8188eu/core/rtw_mlme.c
> +++ b/drivers/staging/r8188eu/core/rtw_mlme.c
> @@ -1637,26 +1637,13 @@ 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);
> + struct security_priv *p = &Adapter->securitypriv;
> + int i;
>
> - if (i == NUM_PMKID_CACHE) {
> - i = -1;/* Could not find. */
> - } else {
> - /* There is one Pre-Authentication Key for the specific BSSID. */
> - }
> - return 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] 2+ messages in thread
end of thread, other threads:[~2022-04-04 2:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 16:42 [PATCH v2] staging: r8188eu: simplify control flow Sevinj Aghayeva
2022-04-04 2:46 ` 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.