All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: simplify control flow
@ 2022-04-03 15:51 Sevinj Aghayeva
  2022-04-03 15:59 ` Pavel Skripkin
  0 siblings, 1 reply; 7+ messages in thread
From: Sevinj Aghayeva @ 2022-04-03 15:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: 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/r8188eu/core/rtw_mlme.c | 26 +++++++------------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_mlme.c b/drivers/staging/r8188eu/core/rtw_mlme.c
index f94b1536a177..851092f61206 100644
--- a/drivers/staging/r8188eu/core/rtw_mlme.c
+++ b/drivers/staging/r8188eu/core/rtw_mlme.c
@@ -1637,26 +1637,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);
+	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] 7+ messages in thread

* Re: [PATCH] staging: r8188eu: simplify control flow
  2022-04-03 15:51 [PATCH] staging: r8188eu: simplify control flow Sevinj Aghayeva
@ 2022-04-03 15:59 ` Pavel Skripkin
  2022-04-03 16:12   ` Sevinj Aghayeva
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Skripkin @ 2022-04-03 15:59 UTC (permalink / raw)
  To: Sevinj Aghayeva, Greg Kroah-Hartman
  Cc: linux-staging, linux-kernel, outreachy

Hi Sevinj,

On 4/3/22 18:51, 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>
> ---

[code snip]

> +	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;
>   }
>   
>   /*  */

Looks good, but let's not introduce new checkpatch issue:

CHECK: Alignment should match open parenthesis
#62: FILE: drivers/staging/r8188eu/core/rtw_mlme.c:1645:
+		if ((p->PMKIDList[i].bUsed) &&
+				(!memcmp(p->PMKIDList[i].Bssid, bssid, ETH_ALEN)))




With regards,
Pavel Skripkin

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

* Re: [PATCH] staging: r8188eu: simplify control flow
  2022-04-03 15:59 ` Pavel Skripkin
@ 2022-04-03 16:12   ` Sevinj Aghayeva
  2022-04-03 16:16     ` Pavel Skripkin
  0 siblings, 1 reply; 7+ messages in thread
From: Sevinj Aghayeva @ 2022-04-03 16:12 UTC (permalink / raw)
  To: Pavel Skripkin; +Cc: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy

Hi Pavel,

On Sun, Apr 3, 2022 at 11:59 AM Pavel Skripkin <paskripkin@gmail.com> wrote:
>
> Hi Sevinj,
>
> On 4/3/22 18:51, 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>
> > ---
>
> [code snip]
>
> > +     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;
> >   }
> >
> >   /*  */
>
> Looks good, but let's not introduce new checkpatch issue:
>
> CHECK: Alignment should match open parenthesis
> #62: FILE: drivers/staging/r8188eu/core/rtw_mlme.c:1645:
> +               if ((p->PMKIDList[i].bUsed) &&
> +                               (!memcmp(p->PMKIDList[i].Bssid, bssid, ETH_ALEN)))

Thanks for catching this. I wasn't seeing this in my checkpatch
output, and after some digging, I could reproduce it with --strict
option. I think the tutorial at
https://kernelnewbies.org/PatchPhilosophy doesn't mention this option,
so perhaps we should update it?!

>
>
>
>
> With regards,
> Pavel Skripkin



-- 

Sevinj.Aghayeva

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

* Re: [PATCH] staging: r8188eu: simplify control flow
  2022-04-03 16:12   ` Sevinj Aghayeva
@ 2022-04-03 16:16     ` Pavel Skripkin
  2022-04-03 16:29       ` Sevinj Aghayeva
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Skripkin @ 2022-04-03 16:16 UTC (permalink / raw)
  To: Sevinj Aghayeva
  Cc: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy


[-- Attachment #1.1: Type: text/plain, Size: 998 bytes --]

Hi Sevinj,

On 4/3/22 19:12, Sevinj Aghayeva wrote:
>>
>> Looks good, but let's not introduce new checkpatch issue:
>>
>> CHECK: Alignment should match open parenthesis
>> #62: FILE: drivers/staging/r8188eu/core/rtw_mlme.c:1645:
>> +               if ((p->PMKIDList[i].bUsed) &&
>> +                               (!memcmp(p->PMKIDList[i].Bssid, bssid, ETH_ALEN)))
> 
> Thanks for catching this. I wasn't seeing this in my checkpatch
> output, and after some digging, I could reproduce it with --strict
> option. I think the tutorial at
> https://kernelnewbies.org/PatchPhilosophy doesn't mention this option,
> so perhaps we should update it?!
> 

To be honest, I am not checkpatch expert, but checkpatch on my PC shows 
this warning w/o any additional options:

└──$ ./scripts/checkpatch.pl 
./20220403_sevinj_aghayeva_staging_r8188eu_simplify_control_flow.mbx | 
rg Alignment
CHECK: Alignment should match open parenthesis





With regards,
Pavel Skripkin

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

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

* Re: [PATCH] staging: r8188eu: simplify control flow
  2022-04-03 16:16     ` Pavel Skripkin
@ 2022-04-03 16:29       ` Sevinj Aghayeva
  2022-04-03 16:43         ` Michael Straube
  0 siblings, 1 reply; 7+ messages in thread
From: Sevinj Aghayeva @ 2022-04-03 16:29 UTC (permalink / raw)
  To: Pavel Skripkin; +Cc: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy

On Sun, Apr 3, 2022 at 12:16 PM Pavel Skripkin <paskripkin@gmail.com> wrote:
>
> Hi Sevinj,
>
> On 4/3/22 19:12, Sevinj Aghayeva wrote:
> >>
> >> Looks good, but let's not introduce new checkpatch issue:
> >>
> >> CHECK: Alignment should match open parenthesis
> >> #62: FILE: drivers/staging/r8188eu/core/rtw_mlme.c:1645:
> >> +               if ((p->PMKIDList[i].bUsed) &&
> >> +                               (!memcmp(p->PMKIDList[i].Bssid, bssid, ETH_ALEN)))
> >
> > Thanks for catching this. I wasn't seeing this in my checkpatch
> > output, and after some digging, I could reproduce it with --strict
> > option. I think the tutorial at
> > https://kernelnewbies.org/PatchPhilosophy doesn't mention this option,
> > so perhaps we should update it?!
> >
>
> To be honest, I am not checkpatch expert, but checkpatch on my PC shows
> this warning w/o any additional options:
>
> └──$ ./scripts/checkpatch.pl
> ./20220403_sevinj_aghayeva_staging_r8188eu_simplify_control_flow.mbx |
> rg Alignment
> CHECK: Alignment should match open parenthesis

Ah, I see. You run it on an email file that contains the patch. I
could reproduce what you saw when I ran checkpatch without any options
on an email file. But my usual workflow is to modify a file, e.g.
rtw_mlme.c and then run "checkpatch.pl -f rtw_mlme.c", in which case I
cannot see the "Alignment should match" error. So it looks like if you
do not specify -f then checkpatch.pl enables --strict option.

>
>
>
>
>
> With regards,
> Pavel Skripkin



-- 

Sevinj.Aghayeva

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

* Re: [PATCH] staging: r8188eu: simplify control flow
  2022-04-03 16:29       ` Sevinj Aghayeva
@ 2022-04-03 16:43         ` Michael Straube
  2022-04-03 16:59           ` Sevinj Aghayeva
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Straube @ 2022-04-03 16:43 UTC (permalink / raw)
  To: Sevinj Aghayeva, Pavel Skripkin
  Cc: Greg Kroah-Hartman, linux-staging, linux-kernel, outreachy

On 4/3/22 18:29, Sevinj Aghayeva wrote:
> Ah, I see. You run it on an email file that contains the patch. I
> could reproduce what you saw when I ran checkpatch without any options
> on an email file. But my usual workflow is to modify a file, e.g.
> rtw_mlme.c and then run "checkpatch.pl -f rtw_mlme.c", in which case I
> cannot see the "Alignment should match" error. So it looks like if you
> do not specify -f then checkpatch.pl enables --strict option.
> 

Hi Sevinj,

I'm also not a checkpatch expert, but on my system this works without
--strict too. I applied your patch to my local tree and get:

/scripts/checkpatch.pl -f drivers/staging/r8188eu/core/rtw_mlme.c

[snip]

CHECK: Alignment should match open parenthesis
#1638: FILE: drivers/staging/r8188eu/core/rtw_mlme.c:1638:
+               if ((p->PMKIDList[i].bUsed) &&
+                               (!memcmp(p->PMKIDList[i].Bssid, bssid, 
ETH_ALEN)))

[snip]

You can also run checkpatch on the patch files (without -f).
Then it's easier to see if you introduced new issues.

regards,
Michael

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

* Re: [PATCH] staging: r8188eu: simplify control flow
  2022-04-03 16:43         ` Michael Straube
@ 2022-04-03 16:59           ` Sevinj Aghayeva
  0 siblings, 0 replies; 7+ messages in thread
From: Sevinj Aghayeva @ 2022-04-03 16:59 UTC (permalink / raw)
  To: Michael Straube
  Cc: Pavel Skripkin, Greg Kroah-Hartman, linux-staging, linux-kernel,
	outreachy

On Sun, Apr 3, 2022 at 12:43 PM Michael Straube <straube.linux@gmail.com> wrote:
>
> On 4/3/22 18:29, Sevinj Aghayeva wrote:
> > Ah, I see. You run it on an email file that contains the patch. I
> > could reproduce what you saw when I ran checkpatch without any options
> > on an email file. But my usual workflow is to modify a file, e.g.
> > rtw_mlme.c and then run "checkpatch.pl -f rtw_mlme.c", in which case I
> > cannot see the "Alignment should match" error. So it looks like if you
> > do not specify -f then checkpatch.pl enables --strict option.
> >
>
> Hi Sevinj,
>
> I'm also not a checkpatch expert, but on my system this works without
> --strict too. I applied your patch to my local tree and get:
>
> /scripts/checkpatch.pl -f drivers/staging/r8188eu/core/rtw_mlme.c

Hi Michael,

That's odd. I don't get any CHECK messages if I run exactly the same
command as above:

$ pwd
/home/sevinj/k/staging/drivers/staging/r8188eu/core
$ ~/k/staging/scripts/checkpatch.pl -f rtw_mlme.c | grep 'CHECK:' | wc -l
0

I have to specify --strict to get CHECK messages:

$ ~/k/staging/scripts/checkpatch.pl --strict -f rtw_mlme.c | grep
'CHECK:' | wc -l
167

I don't know why that is. I'm on Ubuntu 20.04 and it looks like I'm
running checkpatch version 0.32:

$ ~/k/staging/scripts/checkpatch.pl -h
Usage: /home/sevinj/k/staging/scripts/checkpatch.pl [OPTION]... [FILE]...
Version: 0.32

<snip>

>
> [snip]
>
> CHECK: Alignment should match open parenthesis
> #1638: FILE: drivers/staging/r8188eu/core/rtw_mlme.c:1638:
> +               if ((p->PMKIDList[i].bUsed) &&
> +                               (!memcmp(p->PMKIDList[i].Bssid, bssid,
> ETH_ALEN)))
>
> [snip]
>
> You can also run checkpatch on the patch files (without -f).
> Then it's easier to see if you introduced new issues.
>
> regards,
> Michael



-- 

Sevinj.Aghayeva

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

end of thread, other threads:[~2022-04-03 17:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 15:51 [PATCH] staging: r8188eu: simplify control flow Sevinj Aghayeva
2022-04-03 15:59 ` Pavel Skripkin
2022-04-03 16:12   ` Sevinj Aghayeva
2022-04-03 16:16     ` Pavel Skripkin
2022-04-03 16:29       ` Sevinj Aghayeva
2022-04-03 16:43         ` Michael Straube
2022-04-03 16:59           ` 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.