All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8192u: ieee80211: Move assignment out of the if.
@ 2016-10-19 21:56 Elise Lennion
  2016-10-20  9:03 ` [Outreachy kernel] " Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Elise Lennion @ 2016-10-19 21:56 UTC (permalink / raw)
  To: gregkh, outreachy-kernel

Assignments inside of if statements confuse the reader and should be
avoided, so it was moved out before the if.

Found with Coccinelle, semantic patch:
@@
expression e1, e2;
statement S;
position p;
@@

+ e1 = e2;
if (<+...
- (e1 = e2)
 @p
+ e1
 ...+>)
S

Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
---
 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index 89cbc07..0d81b3a 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -1145,8 +1145,8 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
 
 	/* skb: hdr + (possibly fragmented, possibly encrypted) payload */
 
-	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
-	    (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
+	keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt);
+	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && keyidx < 0)
 	{
 		printk("decrypt frame error\n");
 		goto rx_dropped;
-- 
2.7.4



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

* [PATCH] staging: rtl8192u: ieee80211: Move assignment out of the if.
@ 2016-10-19 22:13 Elise Lennion
  0 siblings, 0 replies; 3+ messages in thread
From: Elise Lennion @ 2016-10-19 22:13 UTC (permalink / raw)
  To: gregkh, outreachy-kernel

Actually, I want to cancel this patch, since C uses short-circuiting on
&& operators and the assignment is the third verification.

sorry,

elise


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

* Re: [Outreachy kernel] [PATCH] staging: rtl8192u: ieee80211: Move assignment out of the if.
  2016-10-19 21:56 [PATCH] staging: rtl8192u: ieee80211: Move assignment out of the if Elise Lennion
@ 2016-10-20  9:03 ` Julia Lawall
  0 siblings, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2016-10-20  9:03 UTC (permalink / raw)
  To: Elise Lennion; +Cc: gregkh, outreachy-kernel



On Wed, 19 Oct 2016, Elise Lennion wrote:

> Assignments inside of if statements confuse the reader and should be
> avoided, so it was moved out before the if.
>
> Found with Coccinelle, semantic patch:
> @@
> expression e1, e2;
> statement S;
> position p;
> @@
>
> + e1 = e2;
> if (<+...
> - (e1 = e2)
>  @p
> + e1
>  ...+>)
> S
>
> Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
> ---
>  drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> index 89cbc07..0d81b3a 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> @@ -1145,8 +1145,8 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
>
>  	/* skb: hdr + (possibly fragmented, possibly encrypted) payload */
>
> -	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) &&
> -	    (keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt)) < 0)
> +	keyidx = ieee80211_rx_frame_decrypt(ieee, skb, crypt);
> +	if (ieee->host_decrypt && (fc & IEEE80211_FCTL_WEP) && keyidx < 0)

Yeah, this is indeed not a good idea.

julia

>  	{
>  		printk("decrypt frame error\n");
>  		goto rx_dropped;
> --
> 2.7.4
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20161019215641.GA309%40lennorien.com.
> For more options, visit https://groups.google.com/d/optout.
>


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

end of thread, other threads:[~2016-10-20  9:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-19 21:56 [PATCH] staging: rtl8192u: ieee80211: Move assignment out of the if Elise Lennion
2016-10-20  9:03 ` [Outreachy kernel] " Julia Lawall
  -- strict thread matches above, loose matches on Subject: below --
2016-10-19 22:13 Elise Lennion

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.