staging: r8188eu: simplify control flow
PATCH 1/1 staging: r8188eu: simplify control flow
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
--- drivers/staging/r8188eu/core/rtw_mlme.c | 26 +++++++------------------ 1 file changed, 7 insertions(+), 19 deletions(-)
drivers/staging/r8188eu/core/rtw_mlme.c +7 -19
@@ -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 ; }/* */
Signature · 1 line
2.25.1
Hi Sevinj,
Quoted 8 lines · Sevinj Aghayeva
The function iterates an index from 0 to
NUM_PMKID_CACHEand 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.
Quoted 6 lines
Reported by checkpatch:
WARNING: else is not generally useful after a break or return
Signed-off-by Sevinj Aghayeva <[email protected]>---
[code snip]
drivers/staging/r8188eu/core/rtw_mlme.c int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_ · line 1650
Quoted 8 lines
drivers/staging/r8188eu/core/rtw_mlme.c +5
-0+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
Hi Pavel,
Quoted 34 lines · Pavel Skripkin
Hi Sevinj,
Quoted 8 lines · Sevinj Aghayeva
The function iterates an index from 0 to
NUM_PMKID_CACHEand 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.
Quoted 6 lines
Reported by checkpatch:
WARNING: else is not generally useful after a break or return
Signed-off-by Sevinj Aghayeva <[email protected]>---
[code snip]
drivers/staging/r8188eu/core/rtw_mlme.c int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_ · line 1650
Quoted 8 lines
drivers/staging/r8188eu/core/rtw_mlme.c +5
-0+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:
drivers/staging/r8188eu/core/rtw_mlme.c int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_ · line 1645
Quoted 2 lines
drivers/staging/r8188eu/core/rtw_mlme.c +2
-0+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?!
Quoted 6 lines
With regards,
Pavel Skripkin
Signature · 1 line
Sevinj.Aghayeva
Hi Sevinj,
Quoted 8 lines · Sevinj Aghayeva
drivers/staging/r8188eu/core/rtw_mlme.c int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_ · line 1645
Quoted 7 lines
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:drivers/staging/r8188eu/core/rtw_mlme.c +2
-0+if ((p->PMKIDList[i].bUsed) && + (!memcmp (p->PMKIDList[i].Bssid, bssid,ETH_ALEN )))
Quoted 6 lines
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
Quoted 19 lines · Pavel Skripkin
Hi Sevinj,
Quoted 8 lines · Sevinj Aghayeva
drivers/staging/r8188eu/core/rtw_mlme.c int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_ · line 1645
Quoted 7 lines
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:drivers/staging/r8188eu/core/rtw_mlme.c +2
-0+if ((p->PMKIDList[i].bUsed) && + (!memcmp (p->PMKIDList[i].Bssid, bssid,ETH_ALEN )))Quoted 6 lines
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?!
Quoted 7 lines
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.
Quoted 7 lines
With regards,
Pavel Skripkin
Signature · 1 line
Sevinj.Aghayeva
Quoted 7 lines · Sevinj Aghayeva
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.cand then run "checkpatch.pl -frtw_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
Quoted 10 lines · Michael Straube
Quoted 7 lines · Sevinj Aghayeva
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.cand then run "checkpatch.pl -frtw_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.
Quoted 6 lines
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>
Quoted 16 lines
[snip]
CHECK: Alignment should match open parenthesis #1638: FILE:
drivers/staging/r8188eu/core/rtw_mlme.c:1638:(quoted diff) +2
-0+ 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
Signature · 1 line
Sevinj.Aghayeva