linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8188eu: core: switch with redundant cases
@ 2015-02-04 11:04 Nicholas Mc Guire
  2015-02-04 11:42 ` Dan Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Nicholas Mc Guire @ 2015-02-04 11:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: navin patidar, Larry Finger, Abel Moyo, devel, linux-kernel,
	Nicholas Mc Guire

A few redundant switch cases as well as a redundant if/else
within one of the cases was consolidated to a single call.
The cases are intentionally retained for documentation purposes.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---
case WIFI_REASSOCREQ,WIFI_PROBEREQ,WIFI_BEACON,WIFI_ACTION all
have the same effect - notably the also for WIFI_PROBEREQ where
the if/else is executing the same function. 

These redundant cases could all be dropped and consolidated into
the default but probably it is better for documentation/readability
to leave them in the switch/case explicitly.

Patch was only compile-tested for x86_64_defconfig + CONFIG_STAGING=y
CONFIG_R8188EU=m

Patch is against 3.19.0-rc7 (localversion-next is -next-20150204)

 drivers/staging/rtl8188eu/core/rtw_mlme_ext.c |    9 ---------
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index 28918201..cd12dd7 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -484,17 +484,8 @@ void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame)
 		/* fall through */
 	case WIFI_ASSOCREQ:
 	case WIFI_REASSOCREQ:
-		_mgt_dispatcher(padapter, ptable, precv_frame);
-		break;
 	case WIFI_PROBEREQ:
-		if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
-			_mgt_dispatcher(padapter, ptable, precv_frame);
-		else
-			_mgt_dispatcher(padapter, ptable, precv_frame);
-		break;
 	case WIFI_BEACON:
-		_mgt_dispatcher(padapter, ptable, precv_frame);
-		break;
 	case WIFI_ACTION:
 		_mgt_dispatcher(padapter, ptable, precv_frame);
 		break;
-- 
1.7.10.4


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

* Re: [PATCH] staging: rtl8188eu: core: switch with redundant cases
  2015-02-04 11:04 [PATCH] staging: rtl8188eu: core: switch with redundant cases Nicholas Mc Guire
@ 2015-02-04 11:42 ` Dan Carpenter
  2015-02-04 11:43 ` Dan Carpenter
  2015-02-04 12:07 ` Rasmus Villemoes
  2 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2015-02-04 11:42 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Greg Kroah-Hartman, devel, linux-kernel, Abel Moyo, Larry Finger

On Wed, Feb 04, 2015 at 06:04:38AM -0500, Nicholas Mc Guire wrote:
> A few redundant switch cases as well as a redundant if/else
> within one of the cases was consolidated to a single call.
> The cases are intentionally retained for documentation purposes.

This statement is not clear.  It obviously causes a bug if you just
start deleting case statements.

> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> ---
> case WIFI_REASSOCREQ,WIFI_PROBEREQ,WIFI_BEACON,WIFI_ACTION all
> have the same effect - notably the also for WIFI_PROBEREQ where
> the if/else is executing the same function. 
> 
> These redundant cases could all be dropped and consolidated into
> the default but probably it is better for documentation/readability
> to leave them in the switch/case explicitly.

Oh.  This explains what you meant.  Stop putting this information below
the cut off, it's annoying.

regards,
dan carpenter


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

* Re: [PATCH] staging: rtl8188eu: core: switch with redundant cases
  2015-02-04 11:04 [PATCH] staging: rtl8188eu: core: switch with redundant cases Nicholas Mc Guire
  2015-02-04 11:42 ` Dan Carpenter
@ 2015-02-04 11:43 ` Dan Carpenter
  2015-02-04 13:16   ` Nicholas Mc Guire
  2015-02-04 12:07 ` Rasmus Villemoes
  2 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2015-02-04 11:43 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Greg Kroah-Hartman, devel, linux-kernel, Abel Moyo, Larry Finger

Btw, what tool are you using to find these?

regards,
dan carpenter


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

* Re: [PATCH] staging: rtl8188eu: core: switch with redundant cases
  2015-02-04 11:04 [PATCH] staging: rtl8188eu: core: switch with redundant cases Nicholas Mc Guire
  2015-02-04 11:42 ` Dan Carpenter
  2015-02-04 11:43 ` Dan Carpenter
@ 2015-02-04 12:07 ` Rasmus Villemoes
  2 siblings, 0 replies; 5+ messages in thread
From: Rasmus Villemoes @ 2015-02-04 12:07 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Greg Kroah-Hartman, devel, linux-kernel, Abel Moyo, Larry Finger

On Wed, Feb 04 2015, Nicholas Mc Guire <hofrat@osadl.org> wrote:

> A few redundant switch cases as well as a redundant if/else
> within one of the cases was consolidated to a single call.
> The cases are intentionally retained for documentation purposes.
>
[...]
> diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
> index 28918201..cd12dd7 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
> @@ -484,17 +484,8 @@ void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame)
>  		/* fall through */
>  	case WIFI_ASSOCREQ:
>  	case WIFI_REASSOCREQ:
> -		_mgt_dispatcher(padapter, ptable, precv_frame);
> -		break;
>  	case WIFI_PROBEREQ:
> -		if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
> -			_mgt_dispatcher(padapter, ptable, precv_frame);
> -		else
> -			_mgt_dispatcher(padapter, ptable, precv_frame);

It is highly unlikely that a function called check_fwstate has side
effects, but it might be nice checking that and making a note in the
commit log.

Rasmus

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

* Re: [PATCH] staging: rtl8188eu: core: switch with redundant cases
  2015-02-04 11:43 ` Dan Carpenter
@ 2015-02-04 13:16   ` Nicholas Mc Guire
  0 siblings, 0 replies; 5+ messages in thread
From: Nicholas Mc Guire @ 2015-02-04 13:16 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Nicholas Mc Guire, Greg Kroah-Hartman, devel, linux-kernel,
	Abel Moyo, Larry Finger

On Wed, 04 Feb 2015, Dan Carpenter wrote:

> Btw, what tool are you using to find these?
>
working on a set of coccinell scripts - they are not yet
really clean - but this one is simply:


virtual context
virtual patch
virtual org
virtual report

@assign@
position p;
statement S1;
@@

<+...
* if@p (...) S1 else S1
...+>

@script:python@
p << assign.p;
@@

print "%s:%s WARNING: condition with no effect" % (p[0].file,p[0].line)



I guess this is not wildly impressive - but it seems to be effective
in finding a lot of broken code. The rate of false postivs has been
supprisingly low (very few case of intentional if==else like in
./fs/kernfs/file.c:661 - which is nicely documented)

thx!
hofrat
 

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

end of thread, other threads:[~2015-02-04 13:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-04 11:04 [PATCH] staging: rtl8188eu: core: switch with redundant cases Nicholas Mc Guire
2015-02-04 11:42 ` Dan Carpenter
2015-02-04 11:43 ` Dan Carpenter
2015-02-04 13:16   ` Nicholas Mc Guire
2015-02-04 12:07 ` Rasmus Villemoes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).